c# outlook add-in convert msg to eml

瘦欲@ 提交于 2021-02-07 14:53:07

问题


Is there any way to read a mail within outlook (using an add-in) and save it as an EML file?


回答1:


You can go two ways to achieve your goal:

  1. You can do it programmatically. Try to use a third-party library Aspose.Email for .Net. This is a great library, which can be used for basic email management features. In this case, we will use a converting. Furthermore, this library is able to manipulate and edit messages, send and receive emails via several protocols and work with message storage files.

With the following code, you can easily convert MSG to EML. Look how simple it is with Aspose.Email for .NET.

using (var message = Aspose.Email.MailMessage.Load("template.msg»))
{  
    message.Save("output.eml", Aspose.Email.SaveOptions.DefaultEml); 
}
  1. Use online converters. If you don’t want to do it programmatically, you can do it with online converters. You can use Aspose.Email Conversion. This is a free online converter, which provides you with converting from MSG to a bunch of different file formats. It has a friendly user-interface.



回答2:


You can either

1) Create MIME file explicitly in your code one property at a time. You can also use existing MIME converters (I used Lumisoft in the past) - but they won't convert Outlook messages in a single call; you will need to explicitly build all the headers and MIME parts.

2) Use IConverterSession object (C++ or Delphi only) - this is the same MIME converter used by Outlook. You can play with it in OutlookSpy (click IConverterSession button).

3) Use Redemption and its RDOMail.SaveAs or SafeMailItem.SaveAs methods - it can save in the MIME format (olRfc822) along with a dozen or so other formats. It uses IConverterSession object when it is available (Outlook 2003 and up) or its own converter for an older version of Outlook or when used against the Exchange version of MAPI.
The following script (VBS) will save the currently selected message in Outlook as an EML file

  set Session = CreateObject("Redemption.RDOSession")
  Session.MAPIOBJECT = Application.Session.MAPIOBJECT
  set rItem = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
  rItem.SaveAs "c:\temp\test.eml", 1024


来源:https://stackoverflow.com/questions/5594445/c-sharp-outlook-add-in-convert-msg-to-eml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!