bump product version to 4.1.6.2
[LibreOffice.git] / shell / source / win32 / workbench / TestSmplMail.cxx
blob1b610bcc9851f8eb9c506dc2cabc70ab8653c589
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/lang/XComponent.hpp>
21 #include <com/sun/star/registry/XSimpleRegistry.hpp>
22 #include <com/sun/star/system/XSimpleMailClientSupplier.hpp>
23 #include <cppuhelper/servicefactory.hxx>
24 #include <rtl/ustring.hxx>
25 #include <sal/types.h>
26 #include <osl/diagnose.h>
28 #include <stdio.h>
29 #if defined _MSC_VER
30 #pragma warning(push, 1)
31 #endif
32 #include <windows.h>
33 #if defined _MSC_VER
34 #pragma warning(pop)
35 #endif
37 #include <osl/file.hxx>
39 //--------------------------------------------------------------
40 // namesapces
41 //--------------------------------------------------------------
43 using namespace ::rtl ;
44 using namespace ::cppu ;
45 using namespace ::com::sun::star::uno ;
46 using namespace ::com::sun::star::lang ;
47 using namespace std ;
48 using namespace com::sun::star::system;
50 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
52 //--------------------------------------------------------------
53 // global variables
54 //--------------------------------------------------------------
56 Reference< XMultiServiceFactory > g_xFactory;
58 //--------------------------------------------------------------
59 // main
60 //--------------------------------------------------------------
63 // int SAL_CALL main(int nArgc, char* Argv[], char* pEnv[] )
64 // make Warning free, leave out typename
65 int SAL_CALL main(int , char*, char* )
67 //-------------------------------------------------
68 // get the global service-manager
69 //-------------------------------------------------
71 // Get global factory for uno services.
72 OUString rdbName = OUString( RDB_SYSPATH );
73 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
75 // Print a message if an error occurred.
76 if ( g_xFactory.is() == sal_False )
78 OSL_FAIL("Can't create RegistryServiceFactory");
79 return(-1);
82 printf("Creating RegistryServiceFactory successful\n");
84 //-------------------------------------------------
85 // try to get an Interface to a XFilePicker Service
86 //-------------------------------------------------
88 try
90 Reference< XSimpleMailClientSupplier > xSmplMailClientSuppl(
91 g_xFactory->createInstance( OUString("com.sun.star.system.SimpleSystemMail") ), UNO_QUERY );
93 if ( !xSmplMailClientSuppl.is() )
95 OSL_FAIL( "Error creating SimpleSystemMail Service" );
96 return(-1);
99 Reference< XSimpleMailClient > xSmplMailClient(
100 xSmplMailClientSuppl->querySimpleMailClient( ) );
102 if ( xSmplMailClient.is( ) )
104 Reference< XSimpleMailMessage > xSmplMailMsg(
105 xSmplMailClient->createSimpleMailMessage( ) );
107 if ( xSmplMailMsg.is( ) )
109 xSmplMailMsg->setRecipient( OUString("tino.rachui@germany.sun.com") );
110 xSmplMailMsg->setOriginator( OUString("tino.rachui@germany.sun.com") );
112 Sequence< OUString > ccRecips( 1 );
113 ccRecips[0] = OUString("tino.rachui@germany.sun.com");
115 xSmplMailMsg->setCcRecipient( ccRecips );
117 Sequence< OUString > bccRecips( 1 );
118 bccRecips[0] = OUString("tino.rachui@germany.sun.com");
120 xSmplMailMsg->setBccRecipient( bccRecips );
122 xSmplMailMsg->setSubject( OUString("Mapi Test") );
124 Sequence< OUString > attachements( 2 );
126 OUString aFile("D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testprx.exe");
127 OUString aFileURL;
129 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
130 attachements[0] = aFileURL;
132 aFile = OUString("D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testsyssh.exe");
133 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
135 attachements[1] = aFile;
137 xSmplMailMsg->setAttachement( attachements );
139 xSmplMailClient->sendSimpleMailMessage( xSmplMailMsg, 0 );
143 catch( Exception& )
147 //--------------------------------------------------
148 // shutdown
149 //--------------------------------------------------
151 // Cast factory to XComponent
152 Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
154 // Print a message if an error occurred.
155 if ( xComponent.is() == sal_False )
157 OSL_FAIL("Error shuting down");
160 // Dispose and clear factory
161 xComponent->dispose();
162 g_xFactory.clear();
163 g_xFactory = Reference< XMultiServiceFactory >();
165 printf("Test successful\n");
167 return 0;
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */