MAPI Code Example and Documentation

Apr 24, 2012 at 6:31 PM

I am trying to access (download) volumes of emails from Exchange server periodically. EWS won't be a choice because the concern of performance due to the amount of data.

MAPI seems to be the choice for this task. But I am having some difficulties to find the code example with some good documentations. Also with MAPI Reference page, I am not sure if I find the correct place.

This seems to be under the context of outlook. I don't need to go through Outlook. I need to access Exchange server directly.

Your help is highly appreciated. Thx.

Apr 24, 2012 at 6:46 PM

You might look at the MrMAPI build of the MFCMAPI project.

Apr 24, 2012 at 7:14 PM

Thx again for the reply. You mean I should look at the MrMAPI build?

Would you mind explain in some details what I should look for?

I need to grammatically logon to an email account, retrieve the list of folders and then download the emails. Later on, I would need to logon using a service (admin) account and then download emails for all the accounts.

Would you please point me to which class(classes) I should look at? The related APIs?



Apr 24, 2012 at 7:32 PM

CDumpStore does much of what you describe. Start at the routine CMainDlg::OnDumpServerContents. I would note that you haven't really defined what it means to you to "download the emails".

Apr 24, 2012 at 8:31 PM

"download the emails" means I need to get all the emails that I need periodically (the delta .. new emails) from the exchange email accounts that I am interested in and write to a storage outside of exchange server organization (for example, a file system).

The format will be different as well. It could be text or xml or something else.

After said that, I would be also interested to know if there is a MAPI API to query the delta emails from last download. Is there any efficient way to do that? Can I mark the emails that I have already downloaded?



Apr 24, 2012 at 8:34 PM

>if there is a MAPI API to query the delta emails from last download

Not really - for something like that you should really be looking at EWS.

Apr 25, 2012 at 3:17 PM

I have created a profile for the exchange service account which has access to other email accounts.

Can I use MFCMAPI to export emails for all email accounts using the service account? Thx.

Apr 25, 2012 at 3:35 PM

All the code needed to do this is in the MFCMAPI source, but it's not hooked up. I have code in there to export a store, and code in there to walk the server's store table. You'd just need to connect the pieces.

Apr 25, 2012 at 7:35 PM
Edited Apr 25, 2012 at 7:47 PM

Does MFCMAPI support export attachments along with emails? I couldn't locate the attachments after the export.

Also, I have tried to export to an email account which has server size: 54816KB. It has about 283 email/items and about 70 email folders.

It took about 26min to finish the job. Does this sound normal to you?

Or it is too slow. If so, what could be the bottle neck? Is there any statistics or performance report that MFCMAPI provides?



Apr 25, 2012 at 7:52 PM

MFCMAPI makes no effort whatsoever to make its export quick. 26 minutes is actually a pretty good time compared to the last time I tried running it against my own mailbox.

At this point, you have full access to all parts of the code - you can instrument to your heart's content to get the statistics you want.

Attachments - if you're exporting to MSG, they should be in the MSG files.

Apr 25, 2012 at 8:14 PM

Right. I was using Txt (xml) format. There is no attachment exported when using this format.

I also noticed that as text format, user has more flexibilities compared with MSG format.

Txt format can export subfolders, the complete store etc. For MSG, it can only do one folder at a time. It has no sub-folder options.