1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_shell.hxx"
26 
27 
28 //-----------------------------------------------------------
29 //	interface includes
30 //-----------------------------------------------------------
31 #include <com/sun/star/lang/XComponent.hpp>
32 #include <com/sun/star/registry/XSimpleRegistry.hpp>
33 #include <com/sun/star/system/XSystemMailProvider.hpp>
34 #include <cppuhelper/servicefactory.hxx>
35 #include <cppuhelper/servicefactory.hxx>
36 #include <rtl/ustring.hxx>
37 #include <sal/types.h>
38 #include <osl/diagnose.h>
39 
40 #include <stdio.h>
41 #if defined _MSC_VER
42 #pragma warning(push, 1)
43 #endif
44 #include <windows.h>
45 #if defined _MSC_VER
46 #pragma warning(pop)
47 #endif
48 
49 #include <osl/file.hxx>
50 
51 //--------------------------------------------------------------
52 //	namesapces
53 //--------------------------------------------------------------
54 
55 using namespace	::rtl					;
56 using namespace	::cppu					;
57 using namespace	::com::sun::star::uno	;
58 using namespace	::com::sun::star::lang	;
59 using namespace std						;
60 using namespace com::sun::star::system;
61 
62 //--------------------------------------------------------------
63 //	defines
64 //--------------------------------------------------------------
65 
66 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
67 
68 //--------------------------------------------------------------
69 //	global variables
70 //--------------------------------------------------------------
71 
72 Reference< XMultiServiceFactory >	g_xFactory;
73 
74 //--------------------------------------------------------------
75 //	main
76 //--------------------------------------------------------------
77 
78 
79 // int SAL_CALL main(int nArgc, char* Argv[], char* pEnv[]	)
80 // make Warning free, leave out typename
main(int,char *,char *)81 int SAL_CALL main(int , char*, char* )
82 {
83 	//-------------------------------------------------
84 	// get the global service-manager
85 	//-------------------------------------------------
86 
87 	// Get global factory for uno services.
88 	OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) );
89 	Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
90 
91 	// Print a message if an error occurred.
92 	if ( g_xFactory.is() == sal_False )
93 	{
94 		OSL_ENSURE(sal_False, "Can't create RegistryServiceFactory");
95 		return(-1);
96 	}
97 
98 	printf("Creating RegistryServiceFactory successful\n");
99 
100 	//-------------------------------------------------
101 	// try to get an Interface to a XFilePicker Service
102 	//-------------------------------------------------
103 
104     try
105     {
106 	    Reference< XSystemMailProvider > xSmplMailClientSuppl(
107             g_xFactory->createInstance( OUString::createFromAscii( "com.sun.star.system.SimpleSystemMail" ) ), UNO_QUERY );
108 
109 	    if ( !xSmplMailClientSuppl.is() )
110 	    {
111 		    OSL_ENSURE( sal_False, "Error creating SimpleSystemMail Service" );
112 		    return(-1);
113 	    }
114 
115         Reference< XMailClient > xSmplMailClient(
116             xSmplMailClientSuppl->queryMailClient( ) );
117 
118         if ( xSmplMailClient.is( ) )
119         {
120             Reference< XMailMessage > xSmplMailMsg(
121                 xSmplMailClient->createMailMessage( ) );
122 
123             if ( xSmplMailMsg.is( ) )
124             {
125                 xSmplMailMsg->setRecipient( OUString::createFromAscii("tino.rachui@germany.sun.com") );
126                 xSmplMailMsg->setOriginator( OUString::createFromAscii( "tino.rachui@germany.sun.com" ) );
127 
128                 Sequence< OUString > ccRecips( 1 );
129                 ccRecips[0] = OUString::createFromAscii( "tino.rachui@germany.sun.com" );
130 
131                 xSmplMailMsg->setCcRecipient( ccRecips );
132 
133                 Sequence< OUString > bccRecips( 1 );
134                 bccRecips[0] = OUString::createFromAscii( "tino.rachui@germany.sun.com" );
135 
136                 xSmplMailMsg->setBccRecipient( bccRecips );
137 
138                 xSmplMailMsg->setSubject( OUString::createFromAscii( "Mapi Test" ) );
139 
140                 Sequence< OUString > attachements( 2 );
141 
142                 OUString aFile = OUString::createFromAscii( "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testprx.exe" );
143                 OUString aFileURL;
144 
145                 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
146                 attachements[0] = aFileURL;
147 
148                 aFile = OUString::createFromAscii( "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testsyssh.exe" );
149                 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
150 
151                 attachements[1] = aFile;
152 
153                 xSmplMailMsg->setAttachement( attachements );
154 
155                 xSmplMailClient->sendMailMessage( xSmplMailMsg, 0 );
156             }
157         }
158     }
159     catch( Exception& )
160     {
161     }
162 
163 	//--------------------------------------------------
164 	// shutdown
165 	//--------------------------------------------------
166 
167 	// Cast factory to XComponent
168 	Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
169 
170 	// Print a message if an error occurred.
171 	if ( xComponent.is() == sal_False )
172 	{
173 		OSL_ENSURE(sal_False, "Error shutting down");
174 	}
175 
176 	// Dispose and clear factory
177 	xComponent->dispose();
178 	g_xFactory.clear();
179 	g_xFactory = Reference< XMultiServiceFactory >();
180 
181 	printf("Test successful\n");
182 
183 	return 0;
184 }
185