In this article, I would like to tell you how to read the SMS, MMS, and Emails data from your Windows Mobile device. Also I’ll describe some differences between reading message body in Windows Mobile 5 and Windows Mobile 6 devices.
In this article, you can also find information about how to read message recipients.
The Mail API on Pocket PC provides you with a set of COM interfaces that are used primarily for work with the data associated with e-mail. You can get data from the messages using this API.
Here you can see the Mail API Object Model:
Bellow you can see how the MAPI component object architecture relates to the mail client on the Windows Mobile device.
Here are some interfaces of the Mail API Object Model:
IMAPISessioninterface is the parent object that you use when working with MAPI. It is used to initialize MAPI and enables you to log on to a message store.
IMsgStoreinterface is used to provide access to the file storage associated with a specific e-mail transport.
IMAPIFolderinterface is used to access messages and subfolders contained within a message store.
IMAPITableinterface is used to view collections of MAPI objects. For example, the MAPI folder will contain a table of messages.
IMAPIPropinterface is used to set and retrieve MAPI object properties.
IMessageinterface is used to handle individual e-mail messages.
IAttachinterface is used to handle e-mail message attachments.
Below, I’ll show you how to work with properties. If you want to get a property, you can call the following
lpPropTagArrayparameter is a pointer to the
SPropTagArraystructure that contains an array of property tags, which you want to retrieve from the object.
lpcValuesis the number of properties returned.
SPropValuearray that contains the returned property values.
Note: Property values are returned in the same order that is specified in the
SPropTagArray structure is defined as follows:
SPropValue structure is defined as follows:
For example, I will show you how to read some properties from
SizedSPropTagArray is a macro that helps to initialize the
Sometimes you need to open a large property, such as message attachment or message body. You need to use the
IMAPIProp::OpenProperty() method to access it. This function opens a property value and uses the
IStream interface for reading of the property data in large blocks.
For example, let’s take a look at how to read the body from the
You also need to know how to work with
If you want to read data from the table, you need to use the
SRow structure and the
Remember that whenever you are returned the
SRowSet structure, you also need to call the
MAPIFreeBuffer() functions, accordingly, to properly release any memory that has been allocated.
Let’s talk about how to read the messages from the mobile device.
First of all, you need to open
IMAPISession as follows:
Then you need to enumerate all message stores.
First of all, you have to get the table of all message stores:
Using this table, you can obtain the name of each store. To do that, you should get
pIMapiStoresTable using the
Besides the name, you also need the
IMsgStore object for each store:
IMsgStore object has the following subfolders:
PM_IPM_OUTBOX_ENTRYID, for the Outbox folder
PM_IPM_SENTMAIL_ENTRYID, for the Sent Items folder
PM_IPM_WASTEBASKET_ENTRYID, for the Deleted Items folder
PM_CE_IPM_DRAFTS_ENTRYID, for the Drafts folder
PM_CE_IPM_INBOX_ENTRYID, for the Inbox folder
For example, you can read data from the Outbox folder performing the following steps:
In this section, I described you how to get the body in Raw data, MIME Text, or HTML Body formats. The saving of body data is different on Windows Mobile 5 and Windows Mobile 6 devices. That’s why, here are some notes:
- For Windows Mobile 6:
outgoing mail bodies are stored in:
PR_BODY_Wfor plain text mail
PR_BODY_HTML_A(multibyte, for html mail)
incoming mail bodies are stored in:
- ActiveSync account (both Exchange ActiveSync and PC Sync)
- POP3/IMAP messages come in MIME format and we store the full MIME with body included in
Since MAPI specification does allow you to store info in different ways, you basically need to loop through the possible location of the properties until a match is found to make a robust client app.
You can query
PR_MSG_STATUS and compare it with the following flags:
to determine which properties are used for the current message.
- For Windows Mobile 5.0:
- incoming bodies are stored in
- outgoing mail bodies are stored in
- everything is in the plain text format. There is no HTML support.
Also you can try to read data using other types of the property, such as
PR_BODY_W (for unicode) and
PR_BODY_A (for ASCII):
The sample for MIME text body is as follows:
The sample for HTML body only on Windows Mobile 6 is as follows:
First of all, you need to read the recipient table from the
Then you need to read the number of recipients. You can get this information from
pRecipientTable using the corresponding method:
And as for usual
IMAPITable, you can get the collection of
SRowSet and after that read information about the recipient row:
I hope, this article helped you to get to know about:
- MAPI Object Model and how it relates to the mail client.
- How to work with some MAPI objects and data types.
- How to read messages from the Windows Mobile device.
- The differences between reading message body from Win Mobile 5 and Win Mobile 6.
In this article, I didn’t show how to work with attachments and didn’t describe the problem of reading MMS bodies from Windows Mobile 6 devices.
Download Sources of the example (ZIP, 12 KB)