Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
4/8/2010

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

To create a message object

  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:

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

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

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

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

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

Example

The following code example demonstrates how to create a message.

Note:
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.
Copy Code
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

Compiling the Code

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.

    Copy Code
    #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 Pagesdialog box appears.

    2. In the dialog box, navigate to the Inputproperty page for the Linker(navigate to Configuration Properties> Linker> Input).

    3. In Additional Dependencies, type cemapi.lib, and then click OK.

See Also