Download source files - 12 Kb
, 2 simple classes to encapsulate sending mail using the C
alls (CMC) interface.
CMC is a platform independent API which provides messaging capabilities similar to simple MAPI
on Windows. Other obvious API's of use to the MFC programmer are SMTP and Simple MAPI. The
author has provided freeware classes for these at
respectively. This class has been exclusively tested with the MS reference implementation of
CMC but should work ok with any other CMC implementation on Windows 9x, NT and 2000.
- Simple and clean C++ interface.
- All the code is UNICODE compliant and build configurations are provided for this.
Even though Simple MAPI only exports an ASCII versions of it's functions, the class
internally performs the necessary conversions.
- The code can be used in a console application or without bringing up any CMC dialogs
if so desired.
- The code gracefully handles the case where CMC is not installed on client machines.
Internally the class loads the DLL and uses
- To use the class in your code simply include CCmc.cpp in your project and
#include CCmc.h in which ever of your modules needs to make calls to the classes.
- Your code will need to include MFC either statically or dynamically.
- You may want to add xcmc.h to your pre compiled header to improve compilation speed. A
build message will inform you of this.
- To see the class in action, have a look at the code in
InitInstance() in the
V1.0 (25th November 1999)
The API consists of the following 2 classes and their methods and variables:
m_To is of type CStringArray and contains the array of recipients which the email is to
be mailed to. The name of each recipient can be a friendly name (the friendly name is the
name which a recipient with an address book entry is known as e.g. "PJ at Work"
which could map to using an SMTP transport to send to email@example.com)
or it can be a specific transport address e.g. firstname.lastname@example.org.
m_CC is of type CStringArray and contains the array of recipients which the email will
be Carbon Copied to. The way addresses are specified is the same as for m_To.
m_BCC is of type CStringArray and contains the array of recipients which the email will be
Blind Carbon Copied to. The way addresses are specified is the same as for m_To.
m_sSubject is of type CString and is the subject line of the email.
m_sBody is of type CString and is the body of the email.
m_Attachments is of type CStringArray and is a list of filenames to be included as
attachments in the email.
m_AttachmentTitles is of type CStringArray and contains the titles of what each file
attachment will be known as to recipients of this message. If you leave this array empty
then the title will be the same as the filename. As an example have a look at the code in
InitInstance in app.cpp to see how the "autoexec.bat" attachment has a title of
Standard constructor for the class. This class is the main CMC support class and contains
the functions to actually send the mail message.
Standard destructor for the class. Internally this logs you out of CMC if you're logged
in and unloads the CMC dll.
- BOOL Logon(const CString& sProfileName, const CString& sPassword = CString(), CWnd* pParentWnd = NULL);
TRUE if you were successfully logged in to CMC otherwise FALSE.
- sProfileName -- CMC profile name to use to logon.
- sPassword -- sPassword associated with the profile (if any).
- pParentWnd -- The parent window indicating that if a dialog box is displayed, it
is modal with respect to.
Logons to the CMC messaging system creating a session with it. If you pass an empty profile
name then Logon will try to interactively logon by presenting the normal CMC logon dialog.
Specifying NULL as the parent window as is the default will use the window as returned by
AfxGetMainWnd(). Please note that you must be logged on to CMC prior to
sending a message. Internally the code will
ASSERT to ensure you do not forget
to do this.
- BOOL LoggedOn() const;
Simply accessor which returns TRUE if this instance is logged on to CMC otherwise FALSE.
- BOOL Logoff();
TRUE if you were successfully logged off from CMC otherwise FALSE.
The corollary function to Logon. Internally this function is called in the CCMCSession
- BOOL Send(CCMCMessage& message);
TRUE if the message was successfully sent otherwise FALSE.
- message -- Message to be sent.
Sends the message as specified in the message parameter, using the CMC profile
currently logged into.
- BOOL CMCInstalled() const;
Simply accessor which returns TRUE if CMC is installed and has been correctly initialized
ready for this instance to use. The actual loading of the CMC dll is handled internally by
the CCMCSession constructor, meaning it is valid this function anytime after you have
constructed a CCMCSession instance.
- CMC_return_code GetLastError() const;
The last CMC error generated by this CCMCSession instance.
Since the class uses CMC which has its own way of reporting errors different to the
standard Win32 way (GetLastError), this method allows this value to be retrieved. CMC
errors are documented in the xcmc.h file in your VC include directory.
- Package the code up into an OCX, COM Interface or DLL to allow non-MFC apps to use the code.
- Provide a better sample app. At the moment, it's very much a test program which tests all
of the functions in the classes provided.
- If you have any other suggested improvements, please let me know so that I can incorporate
them into the next release.
Contacting the Author
25th November 1999