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