1 ///////////////////////////////////////////////////////////////////////////////
5 // Desc: This class encapsulates the MAPI and CMC mail functions.
7 // Copyright (c) 2003 Michael Carruth
9 ///////////////////////////////////////////////////////////////////////////////
13 #include <xcmc.h> // CMC function defs
14 #include <mapi.h> // MAPI function defs
17 // STL generates various warnings.
18 // 4100: unreferenced formal parameter
19 // 4663: C++ language change: to explicitly specialize class template...
20 // 4018: signed/unsigned mismatch
21 // 4245: conversion from <a> to <b>: signed/unsigned mismatch
22 #pragma warning(push, 3)
23 #pragma warning(disable: 4100)
24 #pragma warning(disable: 4663)
25 #pragma warning(disable: 4018)
26 #pragma warning(disable: 4245)
30 typedef std::pair
<string
,string
> TStrStrPair
;
31 typedef std::vector
<TStrStrPair
> TStrStrVector
;
32 #endif // !defined TStrStrVector
35 // Define CMC entry points
37 typedef CMC_return_code (FAR PASCAL
*LPCMCLOGON
) \
38 (CMC_string
, CMC_string
, CMC_string
, CMC_object_identifier
, \
39 CMC_ui_id
, CMC_uint16
, CMC_flags
, CMC_session_id FAR
*, \
42 typedef CMC_return_code (FAR PASCAL
*LPCMCSEND
) \
43 (CMC_session_id
, CMC_message FAR
*, CMC_flags
, \
44 CMC_ui_id
, CMC_extension FAR
*);
46 typedef CMC_return_code (FAR PASCAL
*LPCMCLOGOFF
) \
47 (CMC_session_id
, CMC_ui_id
, CMC_flags
, CMC_extension FAR
*);
49 typedef CMC_return_code (FAR PASCAL
*LPCMCQUERY
) \
50 (CMC_session_id
, CMC_enum
, CMC_buffer
, CMC_extension FAR
*);
53 ////////////////////////////// Class Definitions /////////////////////////////
55 // ===========================================================================
58 // See the module comment at top of file.
66 //-----------------------------------------------------------------------------
68 // Sets the Email:To address
72 // sName Optional name
78 // Only one To address can be set. If called more than once
79 // the last address will be used.
87 //-----------------------------------------------------------------------------
89 // Sets the Email:Cc address
93 // sName Optional name
99 // Multiple Cc addresses can be set.
104 string sName
= _T("")
107 //-----------------------------------------------------------------------------
109 // Sets the Email:Bcc address
113 // sName Optional name
116 // CMailMsg reference
119 // Multiple Bcc addresses can be set.
124 string sName
= _T("")
127 //-----------------------------------------------------------------------------
129 // Sets the Email:From address
133 // sName Optional name
136 // CMailMsg reference
139 // Only one From address can be set. If called more than once
140 // the last address will be used.
145 string sName
= _T("")
148 //-----------------------------------------------------------------------------
150 // Sets the Email:Subject
156 // CMailMsg reference
164 ) {m_sSubject
= sSubject
; return *this;};
166 //-----------------------------------------------------------------------------
168 // Sets the Email message body
171 // sMessage Message body
174 // CMailMsg reference
182 ) {m_sMessage
= sMessage
; return *this;};
184 //-----------------------------------------------------------------------------
186 // Attaches a file to the email
189 // sAttachment Fully qualified file name
190 // sTitle File display name
193 // CMailMsg reference
201 string sTitle
= _T("")
204 //-----------------------------------------------------------------------------
212 // TRUE if successful
215 // First simple MAPI is used if unsuccessful CMC is used.
221 //-----------------------------------------------------------------------------
223 // Send email using CMC functions.
229 // TRUE if successful
236 //-----------------------------------------------------------------------------
238 // Send email using MAPI functions.
244 // -1: cancelled; 0: other failure; 1: success
251 //-----------------------------------------------------------------------------
253 // Initialize MAPI32.dll
259 // TRUE if successful
266 //-----------------------------------------------------------------------------
268 // Uninitialize MAPI32.dll
282 +------------------------------------------------------------------------------
284 | Function: cResolveName()
286 | Parameters: [IN] lpszName = Name of e-mail recipient to resolve.
287 | [OUT] ppRecips = Pointer to a pointer to an lpMapiRecipDesc
289 | Purpose: Resolves an e-mail address and returns a pointer to a
290 | MapiRecipDesc structure filled with the recipient information
291 | contained in the address book.
293 | Note: ppRecips is allocated off the heap using MAPIAllocateBuffer.
294 | Any user of this method must be sure to release ppRecips when
295 | done with it using either MAPIFreeBuffer or cFreeBuffer.
296 +-------------------------------------------------------------------------------
298 int cResolveName( LHANDLE m_lhSession
, const char * lpszName
, lpMapiRecipDesc
*ppRecip
);
300 TStrStrVector m_from
; // From <address,name>
301 TStrStrVector m_to
; // To <address,name>
302 TStrStrVector m_cc
; // Cc <address,name>
303 TStrStrVector m_bcc
; // Bcc <address,name>
304 TStrStrVector m_attachments
; // Attachment <file,title>
305 string m_sSubject
; // EMail subject
306 string m_sMessage
; // EMail message
308 HMODULE m_hMapi
; // Handle to MAPI32.DLL
309 LPCMCQUERY m_lpCmcQueryConfiguration
; // Cmc func pointer
310 LPCMCLOGON m_lpCmcLogon
; // Cmc func pointer
311 LPCMCSEND m_lpCmcSend
; // Cmc func pointer
312 LPCMCLOGOFF m_lpCmcLogoff
; // Cmc func pointer
313 LPMAPILOGON m_lpMapiLogon
; // Mapi func pointer
314 LPMAPISENDMAIL m_lpMapiSendMail
; // Mapi func pointer
315 LPMAPILOGOFF m_lpMapiLogoff
; // Mapi func pointer
316 LPMAPIRESOLVENAME m_lpMapiResolveName
; // Mapi func pointer
317 LPMAPIFREEBUFFER m_lpMapiFreeBuffer
; // Mapi func pointer
319 BOOL m_bReady
; // MAPI is loaded