API将邮件保存到msg文件

API将邮件保存到msg文件

本文介绍了使用EWS API将邮件保存到msg文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Exchange Web服务托管API 1.1连接到Exchange Server 2010,然后查找收到的新电子邮件.现在,我想将.msg文件的副本保存到磁盘上的文件夹中.

I'm using Exchange Web Services Managed API 1.1 to connect to Exchange server 2010 and then find out new emails received. Now I want to save a copy of the .msg file to a folder on the disk.

我不想使用任何付费第三方进行集成.

I do not want to use any paid third party to integrate.

任何帮助将不胜感激.

推荐答案

如果您乐意另存为.eml格式,则只需使用EWS即可轻松完成此操作,而无需第三方库. .eml文件将包含所有相同的信息,并且可以由Outlook以与.msg(以及其他程序)相同的方式打开.

If you are happy to save into the .eml format instead, it can be done very easily just using EWS and no third party libraries. The .eml file will contain all the same information and can be opened by Outlook in the same way as .msg (and also by other programs).

message.Load(new PropertySet(ItemSchema.MimeContent));

MimeContent mc = message.MimeContent;
FileStream fs = new FileStream("c:\test.eml", FileMode.Create);

fs.Write(mc.Content, 0, mc.Content.Length);
fs.Close();


已清理代码:


Cleaned up code:

message.Load(new PropertySet(ItemSchema.MimeContent));
var mimeContent = message.MimeContent;

using (var fileStream = new FileStream(@"C:\Test.eml", FileMode.Create))
{
    fileStream.Write(mimeContent.Content, 0, mimeContent.Content.Length);
}

这篇关于使用EWS API将邮件保存到msg文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 14:57