Export (0) Print
Expand All

Creating a Message

Windows Mobile 6.5
4/8/2010

New messages are created from a message store's Drafts folder. After you create a message, you can set its property values (subject, body, list of recipients, and so on) and then send the message.

  1. Initialize the MAPI subsystem, and log onto a MAPI session. For more information, see Beginning a MAPI Session.

  2. Establish a connection to a message store. For more information, see Connecting to a Message Store.

  3. Initialize the property tag array to request the Entry ID property value of the Drafts folder by setting the property tag of the array to PR_CE_IPM_DRAFTS_ENTRYID:

    SPropTagArray STags = { 1, {PR_CE_IPM_DRAFTS_ENTRYID} };
    
  4. Get the Entry ID property value of the Drafts folder by calling IMAPIProp::GetProps on the message store object:

    hr = pStore->GetProps(&STags, 0, &cValues, &pSProps);
    
  5. Open the Drafts folder by calling IMsgStore::OpenEntry for the returned Entry ID:

    hr = pStore->OpenEntry(pSProps[0].Value.bin.cb,
                           (LPENTRYID)pSProps[0].Value.bin.lpb,
                           NULL, 0, &ulObjType, (IUnknown **)&pFldrDrafts);
    
  6. Declare a NULL IMessage interface object, and then create a new message in the Drafts folder by using the IMAPIFolder::CreateMessage method:

    hr = pFldrDrafts->CreateMessage(NULL, 0, &pMsg);
    
  7. If no longer needed, release the message store and Drafts folder by calling MAPI IUnknown::Release on their interface objects, and free the memory allocated for the property value structure by calling MAPIFreeBuffer:

    pStore->Release();
    pFldrDrafts->Release();
    MAPIFreeBuffer(pSProps);
    

The following code example demonstrates how to create a message.

Bb415372.note(en-us,MSDN.10).gifNote:
To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it has been modified to include them.
HRESULT hr;

IMessage    * pMsg        = NULL;
IMsgStore   * pStore      = NULL;
IMAPIFolder * pFldrDrafts = NULL;
SPropValue  * pSProps     = NULL;
SPropTagArray STags       = { 1, {PR_CE_IPM_DRAFTS_ENTRYID} };
ULONG         cValues     = 0;
ULONG         ulObjType   = 0;

hr = pStore->GetProps(&STags, 0, &cValues, &pSProps);

hr = pStore->OpenEntry(pSProps[0].Value.bin.cb, (LPENTRYID)pSProps[0].Value.bin.lpb, NULL, 0, &ulObjType, (IUnknown **)&pFldrDrafts);

hr = pFldrDrafts->CreateMessage(NULL, 0, &pMsg);

pStore->Release();
pFldrDrafts->Release();

MAPIFreeBuffer(pSProps);

pStore      = NULL;
pFldrDrafts = NULL;
pSProps     = NULL;

Both the Windows Mobile Professional SDK and the Windows Mobile Standard SDK ship with a code sample called Sending E-mail, which you can build and run to gain a better understanding of the fundamental messaging concepts. The default location for the sample:

C:\Program Files\Windows Mobile 6.5.3 DTK\Samples\Common\CPP\Win32\SendMail\SendMail.sln

To compile the code sample, you must add references to the CE MAPI type library and the CE MAPI header files, to your project.

  1. Add preprocessor directives that include the header files in with the rest of your project files when you build your project. You do this by typing the following statements at the top of either your main C++ source file or your header file.
    #include <cemapi.h>
    #include <mapidefs.h>
    #include <mapiutil.h>
    #include <mapix.h>
    
  2. Specify a linker dependency to the CE MAPI type library as a project property.
    1. Press Alt+F7, and the Project Property Pages dialog box appears.
    2. In the dialog box, navigate to the Input property page for the Linker (navigate to Configuration Properties > Linker > Input).
    3. In Additional Dependencies, type cemapi.lib, and then click OK.

Community Additions

ADD
Show:
© 2014 Microsoft