Click here to Skip to main content
Click here to Skip to main content

CCmc v1.0 - A CMC Implementation

, 3 Mar 2000
Rate this:
Please Sign up or sign in to vote.
An MFC class to encapsulate sending mail using CMC.
  • Download source files - 12 Kb
  • Introduction

    Welcome to CCMC, 2 simple classes to encapsulate sending mail using the Common Messaging Calls (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 http://indigo.ie/~pjn/smtp.html and http://indigo.ie/~pjn/cmapi.html 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.


    Features
    Usage
    History
    API Reference
    Planned Enhancements
    Contacting the Author


    Features

    • 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 GetProcAddress() calls.


    Usage

    • 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 module app.cpp.


    History

    V1.0 (25th November 1999)
    • Initial public release.


    API Reference

    The API consists of the following 2 classes and their methods and variables:

    CCMCMessage:

    CCMCMessage::m_To
    CCMCMessage::m_CC
    CCMCMessage::m_BCC
    CCMCMessage::m_sSubject
    CCMCMessage::m_sBody
    CCMCMessage::m_Attachments
    CCMCMessage::m_AttachmentTitles

    CCMCSession:

    CCMCSession::CCMCSession
    CCMCSession::~CCMCSession
    CCMCSession::Logon
    CCMCSession::LoggedOn
    CCMCSession::Logoff
    CCMCSession::Send
    CCMCSession::CMCInstalled
    CCMCSession::GetLastError


    CCMCMessage::m_To

    Remarks:
    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 pj.naughter@softech-telecom.com) or it can be a specific transport address e.g. pjn@indigo.ie.


    CCMCMessage::m_CC

    Remarks:
    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.


    CCMCMessage::m_BCC

    Remarks:
    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.


    CCMCMessage::m_sSubject

    Remarks:
    m_sSubject is of type CString and is the subject line of the email.


    CCMCMessage::m_sBody

    Remarks:
    m_sBody is of type CString and is the body of the email.


    CCMCMessage::m_Attachments

    Remarks:
    m_Attachments is of type CStringArray and is a list of filenames to be included as attachments in the email.


    CCMCMessage::m_AttachmentTitles

    Remarks:
    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 "my autoexec.bat".


    CCMCSession::CCMCSession

    CCMCSession();

    Remarks:
    Standard constructor for the class. This class is the main CMC support class and contains the functions to actually send the mail message.


    CCMCSession::~CCMCSession

    ~CCMCSession();

    Remarks:
    Standard destructor for the class. Internally this logs you out of CMC if you're logged in and unloads the CMC dll.


    CChooseDirDlg::Logon

    BOOL Logon(const CString& sProfileName, const CString& sPassword = CString(), CWnd* pParentWnd = NULL);

    Return Value:
    TRUE if you were successfully logged in to CMC otherwise FALSE.

    Parameters:

    • 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.

    Remarks:
    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.


    CChooseDirDlg::LoggedOn

    BOOL LoggedOn() const;

    Remarks:
    Simply accessor which returns TRUE if this instance is logged on to CMC otherwise FALSE.


    CChooseDirDlg::Logoff

    BOOL Logoff();

    Return Value:
    TRUE if you were successfully logged off from CMC otherwise FALSE.

    Remarks:
    The corollary function to Logon. Internally this function is called in the CCMCSession destructor.


    CChooseDirDlg::Send

    BOOL Send(CCMCMessage& message);

    Return Value:
    TRUE if the message was successfully sent otherwise FALSE.

    Parameters:

    • message -- Message to be sent.

    Remarks:
    Sends the message as specified in the message parameter, using the CMC profile currently logged into.


    CChooseDirDlg::CMCInstalled

    BOOL CMCInstalled() const;

    Remarks:
    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.


    CChooseDirDlg::GetLastError

    CMC_return_code GetLastError() const;

    Return Value:
    The last CMC error generated by this CCMCSession instance.

    Remarks:
    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.



    Planned Enhancements

    • 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

    PJ Naughter
    Email: pjn@indigo.ie
    Web: http://www.naughter.com
    25th November 1999


    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    Share

    About the Author

    PJ Naughter

    United States United States
    No Biography provided

    Comments and Discussions

     
    GeneralCannot logon with Windows 2000 PinmemberMalcolm Pirie2-Dec-02 23:56 
    GeneralRe: Cannot logon with Windows 2000 Pinmemberpjnaughter3-Dec-02 12:39 
    GeneralRe: Cannot logon with Windows 2000 PinmemberTim L12-Dec-02 10:56 
    GeneralDead links in the first paragraph PinmemberSoliant27-Oct-02 14:55 
    GeneralRe: Dead links in the first paragraph Pinmemberpjnaughter28-Oct-02 1:17 
    GeneralBUG REPORT&FIX : Send w/o Attachments Pinmemberbushi27-Mar-01 3:14 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Mobile
    Web04 | 2.8.140814.1 | Last Updated 4 Mar 2000
    Article Copyright 2000 by PJ Naughter
    Everything else Copyright © CodeProject, 1999-2014
    Terms of Service
    Layout: fixed | fluid