Monday, March 9, 2009

Extended MAPI Implementation

Howdy! Welcome to yet another programming post. I have spent an entire week figuring out the extended MAPI API and implementing my own class to send emails with attachments. This is pretty old school, since these days you can simply use the SMTP built in functions in C#, but as always, I don't have that luxury. I'm working in Visual Studio 6 MFC.

I found several different implementations and learned alot from each one, but there was one I benefited more from than the others. This wrapper is called TI_MAPI. I was able to look at the source code and figure out what the heck is going on and how to get what I needed to send a message.

First off, you must call MAPILogonEx which will give you a valid session pointer (assuming the call succeeds). You can then use this session pointer to access other objects and interfaces as needed for sending an email message. For example, I used the session pointer to retrieve my Outbox folder from which I created a new message, recipient, attachment, ect. It is really a whole chain of objects you must create/retrieve to get to the next one. I will not detail my wrapper class but give you helpful links so if you run into the same task I did, you will have many sources at your disposal. Oh, one thing to keep in mind when Googling this, there is also a "mobile" version of MAPI. Be sure to check the top of the MSDN page before reading, as the mobile version is different than the "outlook" version.

Lastly, pay very close attention to which flags are getting set. There are properties for each message, recipient, and attachment as you will see in the source code linked below. The flags are very important and those used in the source code may not be exactly what you need for your project. Each function (in MSDN, see links below) will list available flags and you can search on these to get more information.

TI_MAPI
If you're sending an attachment, and the recipient keeps getting a "winmail.dat" file instead, try this approach: SGriffin's Forcing Plain Text
MAPILogonEx
IAddrBook
IMAPISession
IMessage
This is a list of numeric error and success codes that may be returned from extended MAPI. They are different from simple MAPI.

That should be enough to get you started. I would have loved to have this list and source code from the beginning! Happy coding!

V

0 comments: