Mastering CEMAPI

In our recent era of global communications, providing some e-mailing capabilities to an application is more than "nice to have." Mobile applications are no exception here. WinCE e-mailing was available ages ago, since the first versions of WIndows CE were released. Since Pocket PC 2002, Microsoft has decided to change its working message store model and has introduced a new set of interfaces. eVC help proudly states:

"Windows CE Messaging Application Programming Interface (CEMAPI) is for mobile devices, what MAPI is for computers. CEMAPI provides a set of classes, interfaces, functions, and other data types to facilitate the development of messaging applications for mobile devices"

As usual, previous MsgStore functionality was dropped and forgotten. This article's main goal is to highlight how to work with CEMAPI and related stuff.

Getting Started

So what's CEMAPI? You have about 20 interfaces to manage message stores, sessions, filtering incoming messages, and so forth. When you try to work with all this, you'll quickly realize that that is going to be as almost the same fun as the OLE DB jungle. The Pocket PC 2003 SDK has several samples for CEMAPI, so you may get an initial feeling for what it is.

All sets of interfaces may be groupped by their functionality. In the next sections, we will discuss mail folder management, message-related interfaces, and synchronization. You can find more details about CEMAPI here.

CEMAPI Session

The "entry point" of CEMAPI is the IMAPISession interface. It allows you to handle different tasks, among them managing message stores. The Windows CE Inbox is logically organized as a tree with accounts as high-level nodes. There is one default account called "ActiveSync," which gives you an opportunity to synchronize e-mails via MS ActiveSync utility. You also may create your own accounts. Later in this article, we will see how to do it programmatically. In the meantime, what we are interested in is that IMAPISession exposes methods to create, open, and enumerate message stores.

The following sample code illustrates how to open some message store in the Inbox. It uses wrapper classes from the attached sample project:

All of the above is simple enough, so we will move forward to message folders.

Managing Inbox Folders

CEMAPI dedicates a specific interface that allows the programmer work with mail folders—IMAPIFolder. It's some analogue of the file system folder; in other words, you're able to enumerate its contents, manage messages inside it, and so on. There are several standard folders: Inbox, Outbox, Deleted, Drafts, and Sent. Below is a tiny example of opening a folder via the IMsgStore interface: