1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_shell.hxx"
30 
31 
32 //-----------------------------------------------------------
33 //	interface includes
34 //-----------------------------------------------------------
35 #include <com/sun/star/lang/XComponent.hpp>
36 #include <com/sun/star/registry/XSimpleRegistry.hpp>
37 #include <com/sun/star/system/XSimpleMailClientSupplier.hpp>
38 #include <cppuhelper/servicefactory.hxx>
39 #include <cppuhelper/servicefactory.hxx>
40 #include <rtl/ustring.hxx>
41 #include <sal/types.h>
42 #include <osl/diagnose.h>
43 
44 #include <stdio.h>
45 #if defined _MSC_VER
46 #pragma warning(push, 1)
47 #endif
48 #include <windows.h>
49 #if defined _MSC_VER
50 #pragma warning(pop)
51 #endif
52 
53 #include <osl/file.hxx>
54 
55 //--------------------------------------------------------------
56 //	namesapces
57 //--------------------------------------------------------------
58 
59 using namespace	::rtl					;
60 using namespace	::cppu					;
61 using namespace	::com::sun::star::uno	;
62 using namespace	::com::sun::star::lang	;
63 using namespace std						;
64 using namespace com::sun::star::system;
65 
66 //--------------------------------------------------------------
67 //	defines
68 //--------------------------------------------------------------
69 
70 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
71 
72 //--------------------------------------------------------------
73 //	global variables
74 //--------------------------------------------------------------
75 
76 Reference< XMultiServiceFactory >	g_xFactory;
77 
78 //--------------------------------------------------------------
79 //	main
80 //--------------------------------------------------------------
81 
82 
83 // int SAL_CALL main(int nArgc, char* Argv[], char* pEnv[]	)
84 // make Warning free, leave out typename
85 int SAL_CALL main(int , char*, char* )
86 {
87 	//-------------------------------------------------
88 	// get the global service-manager
89 	//-------------------------------------------------
90 
91 	// Get global factory for uno services.
92 	OUString rdbName = OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH ) );
93 	Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
94 
95 	// Print a message if an error occured.
96 	if ( g_xFactory.is() == sal_False )
97 	{
98 		OSL_ENSURE(sal_False, "Can't create RegistryServiceFactory");
99 		return(-1);
100 	}
101 
102 	printf("Creating RegistryServiceFactory successful\n");
103 
104 	//-------------------------------------------------
105 	// try to get an Interface to a XFilePicker Service
106 	//-------------------------------------------------
107 
108     try
109     {
110 	    Reference< XSimpleMailClientSupplier > xSmplMailClientSuppl(
111             g_xFactory->createInstance( OUString::createFromAscii( "com.sun.star.system.SimpleSystemMail" ) ), UNO_QUERY );
112 
113 	    if ( !xSmplMailClientSuppl.is() )
114 	    {
115 		    OSL_ENSURE( sal_False, "Error creating SimpleSystemMail Service" );
116 		    return(-1);
117 	    }
118 
119         Reference< XSimpleMailClient > xSmplMailClient(
120             xSmplMailClientSuppl->querySimpleMailClient( ) );
121 
122         if ( xSmplMailClient.is( ) )
123         {
124             Reference< XSimpleMailMessage > xSmplMailMsg(
125                 xSmplMailClient->createSimpleMailMessage( ) );
126 
127             if ( xSmplMailMsg.is( ) )
128             {
129                 xSmplMailMsg->setRecipient( OUString::createFromAscii("tino.rachui@germany.sun.com") );
130                 xSmplMailMsg->setOriginator( OUString::createFromAscii( "tino.rachui@germany.sun.com" ) );
131 
132                 Sequence< OUString > ccRecips( 1 );
133                 ccRecips[0] = OUString::createFromAscii( "tino.rachui@germany.sun.com" );
134 
135                 xSmplMailMsg->setCcRecipient( ccRecips );
136 
137                 Sequence< OUString > bccRecips( 1 );
138                 bccRecips[0] = OUString::createFromAscii( "tino.rachui@germany.sun.com" );
139 
140                 xSmplMailMsg->setBccRecipient( bccRecips );
141 
142                 xSmplMailMsg->setSubject( OUString::createFromAscii( "Mapi Test" ) );
143 
144                 Sequence< OUString > attachements( 2 );
145 
146                 OUString aFile = OUString::createFromAscii( "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testprx.exe" );
147                 OUString aFileURL;
148 
149                 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
150                 attachements[0] = aFileURL;
151 
152                 aFile = OUString::createFromAscii( "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testsyssh.exe" );
153                 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
154 
155                 attachements[1] = aFile;
156 
157                 xSmplMailMsg->setAttachement( attachements );
158 
159                 xSmplMailClient->sendSimpleMailMessage( xSmplMailMsg, 0 );
160             }
161         }
162     }
163     catch( Exception& )
164     {
165     }
166 
167 	//--------------------------------------------------
168 	// shutdown
169 	//--------------------------------------------------
170 
171 	// Cast factory to XComponent
172 	Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
173 
174 	// Print a message if an error occured.
175 	if ( xComponent.is() == sal_False )
176 	{
177 		OSL_ENSURE(sal_False, "Error shuting down");
178 	}
179 
180 	// Dispose and clear factory
181 	xComponent->dispose();
182 	g_xFactory.clear();
183 	g_xFactory = Reference< XMultiServiceFactory >();
184 
185 	printf("Test successful\n");
186 
187 	return 0;
188 }
189