2
votes

I'm writing an application that monitors an Exchange mailbox using EWS. It saves the attachments of the incoming mails to a network folder.

These files are then used by a 3d party application.

Now I've been asked if it is possible to not only save the attachments but the entire e-mail with attachments still included so it can be opened in Outlook. (no other mailclients need to be supported).

The Exchange server is Exchange 2010 and the application is being written in C# Can this be done using EWS? Or is my only solution to use Interop.Outlook to create a .msg file?

2

2 Answers

2
votes

Which Outlook version are you using? Outlook 2010 can open .EML files, which is the "native" storage format for mails (RFC 2822). In this case, you can use the EWS Webservices (or EWS Managed API) to download the MIME content.

In any other cases, have a look at Outlook Redemption (http://www.dimastr.com/redemption/). It can save items as .msg file and can be used from C#.

2
votes
ExchangeService exchangeService = ...
EmailMessage mailMessage = ...

var propertySet = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent, EmailMessageSchema.IsRead);

exchangeService.LoadPropertiesForItems(mailMessage, propertySet);

File.WriteBytes("filename.eml", mailMessage.MimeContent.Content);