Creating a Message

When creating a new message, some message properties are required and others are optional. For example, it is important that you set the PR_MESSAGE_CLASS property of the message. See step 3 of the following procedure.

For a list of message properties that are automatically set, see Properties Set at Message Creation.

    To create a message
  1. Open the folder in which you want the new message to exist. See Opening an Existing Public Folder and Opening an Existing Private or Personal Folder.
  2. Create a new message with a call to the IMAPIFolder::CreateMessage method. This creates the message object and returns an LPMESSAGE pointer to it, which gives access to the MAPI IMessage interface on the new object.
  3. Be sure to set the PR_MESSAGE_CLASS property. You can set this and other properties on the message by calling IMAPIProp::CopyProps or IMAPIProp::SetProps.
  4. Commit the properties you have set by calling IMAPIProp::SaveChanges. The message will appear in the folder in which it was created.

The following sample code illustrates these steps:

    // Create new message with MAPI call...
        hr = lpNewFolder->CreateMessage(
        NULL,        // Interface ID, must be NULL for client apps
        MAPI_DEFERRED_ERRORS,
        &lpNewMessage);
    
// Set appropriate message properties.  Here's a list of the most common...
    // PR_SENDER_NAME,
    // PR_SENDER_ENTRYID,
    // PR_SENDER_ADDRTYPE,
    // PR_SENDER_EMAIL_ADDRESS,
    // PR_SENT_REPRESENTING_NAME,
    // PR_SENT_REPRESENTING_ENTRYID,
    // PR_SENT_REPRESENTING_ADDRTYPE,
    // PR_SENT_REPRESENTING_EMAIL_ADDRESS,
    // PR_CLIENT_SUBMIT_TIME,
    // PR_MESSAGE_DELIVERY_TIME,
    // PR_IMPORTANCE,
    // PR_EXPIRY_TIME,
    // PR_MESSAGE_ATTACHMENTS,
    // PR_RTF_COMPRESSED or PR_BODY
    // PR_SUBJECT
    // PR_MESSAGE_CLASS
    
    // SaveChanges commits the current state of the message.
    // Must use KEEP_OPEN_READWRITE or KEEP_OPEN_READONLY if you
    // intend to access the message later.
    hr = lpNewMessage->SaveChanges( KEEP_OPEN_READWRITE );
 

Note The maximum number of messages that a folder in a personal folder store (PST) can hold is 16,383. Once this number has been reached, an attempt to create another message in the folder results in the error MAPI_E_TABLE_TOO_BIG being returned by the call to the IMAPIProp::SaveChanges method.