LibreOffice Module shell (master) 1
TestSmplMail.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
27
28#include <stdio.h>
29
30#include <windows.h>
31
32#include <osl/file.hxx>
33
34
35// namespaces
36
37
38using namespace ::cppu ;
39using namespace ::com::sun::star::uno ;
40using namespace ::com::sun::star::lang ;
41using namespace std ;
42using namespace com::sun::star::system;
43
44#define RDB_SYSPATH "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\applicat.rdb"
45
46
47// global variables
48
49
50Reference< XMultiServiceFactory > g_xFactory;
51
52
53// main
54
55
56// int SAL_CALL main(int nArgc, char* Argv[], char* pEnv[] )
57// make Warning free, leave out typename
58int SAL_CALL main(int , char*, char* )
59{
60
61 // get the global service-manager
62
63
64 // Get global factory for uno services.
65 OUString rdbName = OUString( RDB_SYSPATH );
66 Reference< XMultiServiceFactory > g_xFactory( createRegistryServiceFactory( rdbName ) );
67
68 // Print a message if an error occurred.
69 if ( g_xFactory.is() == sal_False )
70 {
71 OSL_FAIL("Can't create RegistryServiceFactory");
72 return(-1);
73 }
74
75 printf("Creating RegistryServiceFactory successful\n");
76
77
78 // try to get an Interface to a XFilePicker Service
79
80
81 try
82 {
83 Reference< XSimpleMailClientSupplier > xSmplMailClientSuppl(
84 g_xFactory->createInstance("com.sun.star.system.SimpleSystemMail"), UNO_QUERY );
85
86 if ( !xSmplMailClientSuppl.is() )
87 {
88 OSL_FAIL( "Error creating SimpleSystemMail Service" );
89 return(-1);
90 }
91
92 Reference< XSimpleMailClient > xSmplMailClient(
93 xSmplMailClientSuppl->querySimpleMailClient( ) );
94
95 if ( xSmplMailClient.is( ) )
96 {
97 Reference< XSimpleMailMessage > xSmplMailMsg(
98 xSmplMailClient->createSimpleMailMessage( ) );
99
100 if ( xSmplMailMsg.is( ) )
101 {
102 xSmplMailMsg->setRecipient( OUString("tino.rachui@germany.sun.com") );
103 xSmplMailMsg->setOriginator( OUString("tino.rachui@germany.sun.com") );
104
105 Sequence<OUString> ccRecips { "tino.rachui@germany.sun.com" };
106
107 xSmplMailMsg->setCcRecipient( ccRecips );
108
109 Sequence<OUString> bccRecips { "tino.rachui@germany.sun.com" };
110
111 xSmplMailMsg->setBccRecipient( bccRecips );
112
113 xSmplMailMsg->setSubject( OUString("Mapi Test") );
114
115 Sequence< OUString > attachments( 2 );
116
117 OUString aFile("D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testprx.exe");
118 OUString aFileURL;
119
120 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
121 attachments[0] = aFileURL;
122
123 aFile = "D:\\Projects\\gsl\\shell\\wntmsci7\\bin\\testsyssh.exe";
124 osl::FileBase::getFileURLFromSystemPath( aFile, aFileURL );
125
126 attachments[1] = aFile;
127
128 xSmplMailMsg->setAttachement( attachments );
129
130 xSmplMailClient->sendSimpleMailMessage( xSmplMailMsg, 0 );
131 }
132 }
133 }
134 catch( Exception& )
135 {
136 }
137
138
139 // shutdown
140
141
142 // Cast factory to XComponent
143 Reference< XComponent > xComponent( g_xFactory, UNO_QUERY );
144
145 // Print a message if an error occurred.
146 if ( xComponent.is() == sal_False )
147 {
148 OSL_FAIL("Error shutting down");
149 }
150
151 // Dispose and clear factory
152 xComponent->dispose();
153 g_xFactory.clear();
154
155 printf("Test successful\n");
156
157 return 0;
158}
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XMultiServiceFactory > g_xFactory
int SAL_CALL main(int, char *, char *)
#define RDB_SYSPATH
@ Exception
SAL_DLLPUBLIC_EXPORT css::uno::Reference< css::lang::XMultiServiceFactory > SAL_CALL createRegistryServiceFactory(OUString const &, OUString const &, sal_Bool, OUString const &)
#define sal_False