1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TestSmplMail.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_shell.hxx"
35 //-----------------------------------------------------------
37 //-----------------------------------------------------------
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include <com/sun/star/registry/XSimpleRegistry.hpp>
40 #include <com/sun/star/system/XSimpleMailClientSupplier.hpp>
41 #include <cppuhelper/servicefactory.hxx>
42 #include <cppuhelper/servicefactory.hxx>
43 #include <rtl/ustring.hxx>
44 #include <sal/types.h>
45 #include <osl/diagnose.h>
49 #pragma warning(push, 1)
56 #include <osl/file.hxx>
58 //--------------------------------------------------------------
60 //--------------------------------------------------------------
62 using namespace ::rtl
;
63 using namespace ::cppu
;
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::lang
;
67 using namespace com::sun::star::system
;
69 //--------------------------------------------------------------
71 //--------------------------------------------------------------
73 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
75 //--------------------------------------------------------------
77 //--------------------------------------------------------------
79 Reference
< XMultiServiceFactory
> g_xFactory
;
81 //--------------------------------------------------------------
83 //--------------------------------------------------------------
86 // int SAL_CALL main(int nArgc, char* Argv[], char* pEnv[] )
87 // make Warning free, leave out typename
88 int SAL_CALL
main(int , char*, char* )
90 //-------------------------------------------------
91 // get the global service-manager
92 //-------------------------------------------------
94 // Get global factory for uno services.
95 OUString rdbName
= OUString( RTL_CONSTASCII_USTRINGPARAM( RDB_SYSPATH
) );
96 Reference
< XMultiServiceFactory
> g_xFactory( createRegistryServiceFactory( rdbName
) );
98 // Print a message if an error occured.
99 if ( g_xFactory
.is() == sal_False
)
101 OSL_ENSURE(sal_False
, "Can't create RegistryServiceFactory");
105 printf("Creating RegistryServiceFactory successful\n");
107 //-------------------------------------------------
108 // try to get an Interface to a XFilePicker Service
109 //-------------------------------------------------
113 Reference
< XSimpleMailClientSupplier
> xSmplMailClientSuppl(
114 g_xFactory
->createInstance( OUString::createFromAscii( "com.sun.star.system.SimpleSystemMail" ) ), UNO_QUERY
);
116 if ( !xSmplMailClientSuppl
.is() )
118 OSL_ENSURE( sal_False
, "Error creating SimpleSystemMail Service" );
122 Reference
< XSimpleMailClient
> xSmplMailClient(
123 xSmplMailClientSuppl
->querySimpleMailClient( ) );
125 if ( xSmplMailClient
.is( ) )
127 Reference
< XSimpleMailMessage
> xSmplMailMsg(
128 xSmplMailClient
->createSimpleMailMessage( ) );
130 if ( xSmplMailMsg
.is( ) )
132 xSmplMailMsg
->setRecipient( OUString::createFromAscii("tino.rachui@germany.sun.com") );
133 xSmplMailMsg
->setOriginator( OUString::createFromAscii( "tino.rachui@germany.sun.com" ) );
135 Sequence
< OUString
> ccRecips( 1 );
136 ccRecips
[0] = OUString::createFromAscii( "tino.rachui@germany.sun.com" );
138 xSmplMailMsg
->setCcRecipient( ccRecips
);
140 Sequence
< OUString
> bccRecips( 1 );
141 bccRecips
[0] = OUString::createFromAscii( "tino.rachui@germany.sun.com" );
143 xSmplMailMsg
->setBccRecipient( bccRecips
);
145 xSmplMailMsg
->setSubject( OUString::createFromAscii( "Mapi Test" ) );
147 Sequence
< OUString
> attachements( 2 );
149 OUString aFile
= OUString::createFromAscii( "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testprx.exe" );
152 osl::FileBase::getFileURLFromSystemPath( aFile
, aFileURL
);
153 attachements
[0] = aFileURL
;
155 aFile
= OUString::createFromAscii( "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testsyssh.exe" );
156 osl::FileBase::getFileURLFromSystemPath( aFile
, aFileURL
);
158 attachements
[1] = aFile
;
160 xSmplMailMsg
->setAttachement( attachements
);
162 xSmplMailClient
->sendSimpleMailMessage( xSmplMailMsg
, 0 );
170 //--------------------------------------------------
172 //--------------------------------------------------
174 // Cast factory to XComponent
175 Reference
< XComponent
> xComponent( g_xFactory
, UNO_QUERY
);
177 // Print a message if an error occured.
178 if ( xComponent
.is() == sal_False
)
180 OSL_ENSURE(sal_False
, "Error shuting down");
183 // Dispose and clear factory
184 xComponent
->dispose();
186 g_xFactory
= Reference
< XMultiServiceFactory
>();
188 printf("Test successful\n");