Click here to Skip to main content
11,409,516 members (62,311 online)
Click here to Skip to main content

CMapi v1.01 - A MAPI Implementation

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

    Welcome to CMapi, 2 simple classes to encapsulate sending mail using Simple MAPI.

    Simple MAPI is a set of functions exported by MAPI32.dll which allows you to send and receive mail in a transport independent way. It is an optional part of all Win32 operating systems since Windows 95 (excluding Windows CE). MAPI is intended more for the corporate environment when compared with the Internet mail standard SMTP e.g. products such as MS Exchange Server use MAPI extensively. Transport providers are available for a number of messaging transports including Exchange Server, SMTP, Fax, cc:Mail CompuServe etc. To be able to specify different transports, MAPI provides the concept of profiles which are setup using the Mail control panel applet.


    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 Mapi dialogs if so desired.
    • The code gracefully handles the case where MAPI 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 cmapi.cpp in your project and #include cmapi.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 mapi.h to your pre compiled header to improve compilation speed. An 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 (14th May 1999)
    • Initial public release.

    V1.01 (5 December 1999)

    • Fixed potential problem where CMapi is used in a console app which was giving an ASSERT.
    • Fixed an assert which can occur if you dismiss the login dialog when doing an interactive MAPI logon.


    API Reference

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

    CMapiMessage:

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


    CMapiSession:

    CMapiSession::CMapiSession
    CMapiSession::~CMapiSession
    CMapiSession::Logon
    CMapiSession::LoggedOn
    CMapiSession::Logoff
    CMapiSession::Send
    CMapiSession::MapiInstalled
    CMapiSession::GetLastError


    CMapiMessage::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" could map to using an SMTP MAPI transport to send to pj.naughter@softech-telecom.com) or it can be a specific transport address e.g. SMTP:pjn@indigo.ie, FAX:34567, etc.


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


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


    CMapiMessage::m_sSubject

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


    CMapiMessage::m_sBody

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


    CMapiMessage::m_Attachments

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


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


    CMapiSession::CMapiSession

    CMapiSession();

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


    CMapiSession::~CMapiSession

    ~CMapiSession();

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


    CMapiSession::Logon

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

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

    Parameters:

    • sProfileName -- MAPI profile name to use to logon.
    • sPassword -- Password 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 MAPI 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 MAPI 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 MAPI prior to sending a message. Internally the code will ASSERT to ensure you do not forget to do this.


    CMapiSession::LoggedOn

    BOOL LoggedOn() const;

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


    CMapiSession::Logoff

    BOOL Logoff();

    Return Value:
    TRUE if you were successfully logged of from MAPI otherwise FALSE.

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


    CMapiSession::Send

    BOOL Send(CMapiMessage& message);

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

    Parameters:

    • message -- Message to be sent.

    Remarks:
    Sends the message as specfied in the "message" parameter, using the MAPI profile currently logged into.


    CMapiSession::MapiInstalled

    BOOL MapiInstalled() const;

    Remarks:
    Simply accessor which returns TRUE if MAPI is installed and has been correctly initialised ready for this instance to use. The actual loading of the MAPI dll is handled internally by the CMapiSession constructor, meaning it is valid this function anytime after you have constructed a CMapiSession instance.


    CMapiSession::GetLastError

    DWORD GetLastError() const;

    Return Value:
    The last MAPI error generated by this CMapiSession instance.

    Remarks:
    Since the class uses MAPI which has its own way of reporting errors different to the standard Win32 way (GetLastError()), this method allows this value to be retreived. MAPI errors are documented in the MAPI.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
    5 December 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

     
    GeneralMy vote of 4 [modified] PinmemberVEMS15-Nov-12 8:32 
    Questioncan't send an unicode e-mail. PinmemberRakesh Pahwa5-Dec-08 20:57 
    QuestionCannot send with Outlook 2003 using interactive mode Pinmemberpscholl5-Dec-07 6:32 
    QuestionProfile password? PinmemberCoderCZ25-Jul-07 4:58 
    GeneralRun Cmapi.exe twice Pinmemberjvsun11-Jul-06 23:54 
    Generalmail sending program Pinmemberrenuchandran21-Feb-06 7:24 
    GeneralRe: mail sending program PinmemberMihai Moga31-Mar-06 3:10 
    Generalplease help me to take a look this error Pinmemberruppee22-Dec-05 9:29 
    GeneralRe: please help me to take a look this error Pinmemberkezhu2-Jan-06 18:32 
    GeneralSending an email As... PinmemberAlexEvans3-Oct-05 20:48 
    GeneralResource leak PinmemberDean M Koska2-Oct-04 7:42 
    GeneralOutlook Dialog Size Pinmemberjung-kreidler6-Jul-04 0:16 
    GeneralRe: Outlook Dialog Size Pinmemberpjnaughter6-Jul-04 11:23 
    GeneralMessage breaked into small piecess Pinmemberimod26-Jun-04 21:47 
    GeneralDetermining if a session exists PinmemberDon Kackman24-Jun-04 16:46 
    GeneralRe: Determining if a session exists Pinmemberpjnaughter25-Jun-04 1:16 
    GeneralSend html message body with MpaiSendMail Pinsusscristian_boghina12-May-04 1:36 
    GeneralSend html message body with MpaiSendMail Pinmembercristian_boghina12-May-04 1:36 
    GeneralRe: Send html message body with MpaiSendMail Pinmemberpjnaughter12-May-04 1:54 
    GeneralUpdating the Outlook Address Book through MAPi calls Pinsussf Goines10-Feb-04 13:06 
    GeneralRe: Updating the Outlook Address Book through MAPi calls Pinmemberpjnaughter10-Feb-04 23:59 
    GeneralRe: Updating the Outlook Address Book through MAPi calls Pinsussf goines11-Feb-04 4:43 
    GeneralMAPI functions PinmemberAnthony_Yio9-Feb-04 16:21 
    GeneralRe: MAPI functions Pinmemberpjnaughter10-Feb-04 11:10 
    QuestionSuppress Outlook dialog? PinsussOrxorand15-Jan-04 2:09 
    AnswerRe: Suppress Outlook dialog? Pinmemberpjnaughter15-Jan-04 3:04 
    Questionhow can i had HTML style content PinmemberFloraMin25-Dec-03 23:05 
    AnswerRe: how can i had HTML style content Pinmemberpjnaughter26-Dec-03 2:55 
    GeneralMail in Outbox Pinmemberfirmwaredude19-Nov-03 14:12 
    GeneralRe: Mail in Outbox Pinmemberpjnaughter20-Nov-03 1:23 
    GeneralMAPI and Outlook XP ! PinmemberHadi Rezaee2-Jun-03 9:45 
    GeneralRe: MAPI and Outlook XP ! Pinmemberpjnaughter2-Jun-03 10:30 
    GeneralRe: MAPI and Outlook XP ! Pinsusslau ui18-Jun-03 23:20 
    GeneralRe: MAPI and Outlook XP ! Pinmemberpjnaughter19-Jun-03 0:05 
    QuestionHow can I know the name of the default MAPI provider? PinmemberNicolas Bonamy21-May-03 22:21 
    GeneralQuestion about MapiSendMail Pinsussarasakumaran11-May-03 13:22 
    GeneralRe: Question about MapiSendMail Pinmemberpjnaughter11-May-03 23:36 
    GeneralProblem with MAPI PinmemberMazdak8-May-03 8:13 
    GeneralRe: Problem with MAPI Pinmemberpjnaughter8-May-03 8:47 
    GeneralRe: Problem with MAPI PinmemberMazdak8-May-03 10:20 
    GeneralMAPI Components PinmemberSergio Fasolo25-Apr-03 6:36 
    GeneralRe: MAPI Components Pinmemberpjnaughter25-Apr-03 6:54 
    Questionhow about "From( ) -- the sender info."? Pinmemberhaipengl8-Feb-03 21:57 
    AnswerRe: how about "From( ) -- the sender info."? Pinmemberpjnaughter9-Feb-03 0:22 
    GeneralRe: how about "From( ) -- the sender info."? Pinmemberhaipengl9-Feb-03 9:36 
    GeneralRe: how about "From( ) -- the sender info."? Pinmemberpjnaughter9-Feb-03 13:54 
    GeneralRe: how about "From( ) -- the sender info."? Pinmemberhaipengl9-Feb-03 15:33 
    GeneralRe: how about "From( ) -- the sender info."? Pinmemberpjnaughter10-Feb-03 0:52 
    GeneralRe: how about "From( ) -- the sender info."? Pinmemberhaipengl10-Feb-03 12:09 
    GeneralMAPI send mail PinsussAnonymous27-Nov-02 5:19 

    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 | Terms of Use | Mobile
    Web03 | 2.8.150414.5 | Last Updated 4 Mar 2000
    Article Copyright 2000 by PJ Naughter
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid