Inserting Mail Messages

    Follow this procedure to insert a new message into a message store folder.
  1. Create the message body and header string.
  2. Create a MailMsg structure.
  3. Point the szBody member of the structure to the message body.
  4. Use MailSetField to put the header string into the pwcHeaders member.
  5. Set the message flags to point to the folder.
  6. Set any other relevant flags, for example, MAIL_STATUS_COMPOSED.
  7. Fill in the dwMsgLen, ftDate, and szSvcNam members, if relevant.
  8. Use MailPut to put the message in the desired folder.

The procedure just described works well for simple mail messages without attachments or for a non-Interpersonal Message (non-IPM), which is any message that is processed by an application, rather than read directly by a user. If you need to add non-IPM properties or attachments to the newly created message, be aware that a transport may be registered to receive database notifications and may attempt to manipulate the message as soon as it is written. For example, a transport may move or delete a message in the Outbox folder before the call to MailPutAttachment. To avoid unexpected deletion, create outgoing messages in the Inbox folder only after the message is completely written to the message store and is ready to be sent. Use MailUpdate—hMail, pmm, FALSE—to move the message to the Outbox folder. Set the Boolean variable to FALSE.