Saving Email to a .MSG File Using the EWS Managed API

My current project is launching a service on an email address based on Microsoft Exchange 2010, designed to apply custom rules for incoming emails.

When I look at possible solutions based on C #, the EWS-driven API seems to be the best API for me. Every email action that I need has been found, but there is one extremely large, missing ... Saving the email in a .msg file. Which is pretty surprising to me, considering how easy this action is from Outlook (just drag and drop from Outlook to any folder).

This is an absolute requirement, as users save their emails by drag and drop. Is there a way I skipped this with EWS? So far, I have found only two paths other than EWS:

  • Using a third-party library, which I'm not sure we can afford (IndependentSoft)
  • Using a more complex method with MessageSave and Outlook rules to perform a custom action (the action "starts MessageSave")

I am very surprised that this basic action requires a lot of work and would like to know if there is an easy way to save email in a .msg file?

In the worst case, is there a non-EWS API based method based on C #?

thanks

Edit:

I studied the export solution .eml . The problem is that we are using Outlook 2007, which does not support eml format. .msg pretty much requires here

+5
source share
2 answers

.msg is a format that uses only appearance and not the exchange server with which you communicate.

In this case, the .eml file can be created quite easily.

See here how you can do this.

+4
source

There is a non-EWS API based on the C # method to do exactly what you are looking for:

http://www.independentsoft.de/exchangewebservices/tutorial/downloadmessagetomsgfile.html

 using System; using System.IO; using System.Net; using Independentsoft.Exchange; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); Service service = new Service("https://myserver3/ews/Exchange.asmx", credential); try { ItemShape itemShape = new ItemShape(ShapeType.Id); FindItemResponse inboxItems = service.FindItem(StandardFolder.Inbox, itemShape); for (int i = 0; i < inboxItems.Items.Count; i++) { Independentsoft.Msg.Message msgFile = service.GetMessageFile(inboxItems.Items[i].ItemId); msgFile.Save("c:\\test\\message" + i + ".msg", true); } } catch (ServiceRequestException ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Error: " + ex.XmlMessage); Console.Read(); } catch (WebException ex) { Console.WriteLine("Error: " + ex.Message); Console.Read(); } } } } 

It offers the function of saving messages and other elements as Outlook.msg files.

0
source

Source: https://habr.com/ru/post/1261517/


All Articles