2

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?

klennepette
  • 3,176
  • 22
  • 23
  • http://stackoverflow.com/questions/6293129/save-mail-to-msg-file-using-ews-api#17580143 –  Jul 23 '13 at 04:48

2 Answers2

2

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#.

Henning Krause
  • 5,302
  • 3
  • 24
  • 37
  • Most people are using Outlook 2007 (myself included) but they will roll out Outlook 2010 in the near future. Thanks for the tip! – klennepette Sep 26 '11 at 14:26
  • I've tested this, and we're going to rollout Outlook 2010 a little sooner for a few people. This will work perfect, thanks! – klennepette Sep 26 '11 at 14:34
  • We've had good luck using Mailbee .NET Converter (http://www.afterlogic.com/mailbee-net/outlook-converter) to convert EML to MSG. – SliverNinja - MSFT Oct 20 '11 at 22:05
2
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);
SaguiItay
  • 2,145
  • 1
  • 18
  • 40
  • Thanks for the comment, I knew I could export a *.eml but I was uner the impression Outlook would not correctly read the file, see also my comments on Henning Krause's answer. – klennepette Sep 26 '11 at 14:36