Bump version to 5.0-14
[LibreOffice.git] / shell / source / win32 / workbench / TestSmplMail.cxx
blob9067b2866f9bb17bde4b23c312f5a31edc04a155
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>
40 // namespaces
43 using namespace ::cppu ;
44 using namespace ::com::sun::star::uno ;
45 using namespace ::com::sun::star::lang ;
46 using namespace std ;
47 using namespace com::sun::star::system;
49 #define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
52 // global variables
55 Reference< XMultiServiceFactory > g_xFactory;
58 // main
62 // int SAL_CALL main(int nArgc, char* Argv[], char* pEnv[] )
63 // make Warning free, leave out typename
64 int SAL_CALL main(int , char*, char* )
67 // get the global service-manager
70 // Get global factory for uno services.
71 OUString rdbName = OUString( RDB_SYSPATH );
72 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
74 // Print a message if an error occurred.
75 if ( g_xFactory.is() == sal_False )
77 OSL_FAIL("Can't create RegistryServiceFactory");
78 return(-1);
81 printf("Creating RegistryServiceFactory successful\n");
84 // try to get an Interface to a XFilePicker Service
87 try
89 Reference< XSimpleMailClientSupplier > xSmplMailClientSuppl(
90 g_xFactory->createInstance("com.sun.star.system.SimpleSystemMail"), UNO_QUERY );
92 if ( !xSmplMailClientSuppl.is() )
94 OSL_FAIL( "Error creating SimpleSystemMail Service" );
95 return(-1);
98 Reference< XSimpleMailClient > xSmplMailClient(
99 xSmplMailClientSuppl->querySimpleMailClient( ) );
101 if ( xSmplMailClient.is( ) )
103 Reference< XSimpleMailMessage > xSmplMailMsg(
104 xSmplMailClient->createSimpleMailMessage( ) );
106 if ( xSmplMailMsg.is( ) )
108 xSmplMailMsg->setRecipient( OUString("tino.rachui@germany.sun.com") );
109 xSmplMailMsg->setOriginator( OUString("tino.rachui@germany.sun.com") );
111 Sequence< OUString > ccRecips( 1 );
112 ccRecips[0] = "tino.rachui@germany.sun.com";
114 xSmplMailMsg->setCcRecipient( ccRecips );
116 Sequence< OUString > bccRecips( 1 );
117 bccRecips[0] = "tino.rachui@germany.sun.com";
119 xSmplMailMsg->setBccRecipient( bccRecips );
121 xSmplMailMsg->setSubject( OUString("Mapi Test") );
123 Sequence< OUString > attachments( 2 );
125 OUString aFile("D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testprx.exe");
126 OUString aFileURL;
128 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
129 attachments[0] = aFileURL;
131 aFile = "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testsyssh.exe";
132 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
134 attachments[1] = aFile;
136 xSmplMailMsg->setAttachement( attachments );
138 xSmplMailClient->sendSimpleMailMessage( xSmplMailMsg, 0 );
142 catch( Exception& )
147 // shutdown
150 // Cast factory to XComponent
151 Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
153 // Print a message if an error occurred.
154 if ( xComponent.is() == sal_False )
156 OSL_FAIL("Error shuting down");
159 // Dispose and clear factory
160 xComponent->dispose();
161 g_xFactory.clear();
163 printf("Test successful\n");
165 return 0;
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */