MAPI Messages

MAPI Messages can be accessed by their unique ID’s. MapiGetNextMsgId is the function that allows to you query for all message ID’s in your Inbox.

A full sample bdf file can be found in the samples directory of your installation.

Getting Message ID’s

To get the first message – simply call:

MapiGetNextMsgId(ghSession, “”, sNextMsgId)

To get the next message pass a message id as second parameter, e.g.:

MapiGetNextMsgId(ghSession, sLastMsgId, sNextMsgId).

The following loop will allow you to iterate through all messages:

sLastMsgId := “”;
while(MapiGetNextMsgId(ghSession, sLastMsgId, sNextMsgId)) do
  SLastMsgId := sNextMsgId;
end;

Access a message

To access message properties (text, sender, recipient, …) you have to call MapiGetMessage. MapiGetMessage returns a message handle on which you can call several different functions to get/set message properties. It is very important to FREE a message handle with MapiFreeMessage after the handle is no longer needed!

A message has the following properties:

  • MAPI_PROP_MSG_SUBJECT

  • MAPI_PROP_MSG_NOTETEXT

  • MAPI_PROP_MSG_MSGTYPE

  • MAPI_PROP_MSG_DATERECEIVED

  • MAPI_PROP_MSG_CONVERSATIONID

  • MAPI_PROP_MSG_SENDER_NAME

  • MAPI_PROP_MSG_SENDER_ADDRESS

  • MAPI_PROP_MSG_RECIPIENT_COUNT

  • MAPI_PROP_MSG_ATTACH_COUNT

Properties can be accessed with MapiGetMessageProperty and MapiSetMessageProperty. If you change a message property you have to save the message with MapiSaveMessage in order to commit the changes.

Access recipients

A message can have multiple recipients. The number of recipients can be accessed with the property MAPI_PROP_MSG_RECIPIENT_COUNT. The recipient itself can be access with MapiGetMessageRecipient and the respective recipient ID. The recipient ID is the index of the recipient where the first index is 0. So – a message with a recipient count value of 2 has recipients with index 0 and 1!

When you set recipients you first have to set the number of recipients in the MAPI_PROP_MSG_RECIPIENT_COUNT and then set each recipient individually with MapiSetMessageRecipient.

Access attachments

Attachments are similar to recipients. First you have to get the number of attachments by getting property MAPI_PROP_MSG_ATTACH_COUNT. Then you can use MapiGetMessageAttachment and the respective attachment ID.

In order to get attachments you have to ensure that you call MapiGetMessage with false for the parameter bSuppressAttachments.

When you set attachments you first have to set the number of attachments in the MAPI_PROP_MSG_ATTACH_COUNT and then set each attachment individually with MapiSetAttachment.