Save Email as MSG file without using Outlook (COM object, etc.) or 3rd party software

牧云@^-^@ 提交于 2019-12-02 10:08:22

问题


Right now, I'm using the Exchange Web Services API with PowerShell to pull down specific emails from exchange and save them as EML files. This works great; however, the user/customer requires the emails to be in msg format. There are two ways that I've seen to do this:

  • Use Outlook/Outlook COM Object
  • Use a 3rd party library or software (like this: http://www.independentsoft.de/exchangewebservices/tutorial/downloadmessagetomsgfile.html)

Are there any other alternatives? I would like to stick with PowerShell if possible, but it seems like EWS might be limited to writing EML files.

There is no flexibility on the MSG vs EML requirement (compliance).

EDIT: This will be run on a server; so I would prefer if this could be done without having Outlook installed.


回答1:


You can still use PowerShell with the Outlook Object Model (OOM), if that's what you are hoping for.

You can also use Redemption, which has more features than OOM (it can also be run in a service, doesn't fire Outlook security prompts, etc.).




回答2:


You can create an MSG file explicitly in your code (it is an OLE storage (IStorage) file and its format is documented) - parse the EML file, then populate various MAPI properties in the MSG file.

You can also use Redemption. Converting an EML file to MSG is as easy as

  RDOSession Session = new RDOSession();
  RDOMail Msg = Session.CreateMessageFromMsgFile(@"c:\temp\YourMsgFile.msg");
  Msg.Import(@"c:\temp\YourEmlFile.eml", rdoSaveAsType.olRFC822);
  Msg.Save();


来源:https://stackoverflow.com/questions/26532393/save-email-as-msg-file-without-using-outlook-com-object-etc-or-3rd-party-sof

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