使用EWS API以MSG格式保存电子邮件 [英] Save emails in MSG format using EWS APIs

查看:143
本文介绍了使用EWS API以MSG格式保存电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在研究一种解决方案,使用EWS API从交换中提取电子邮件,然后在线上传到SharePoint。下面是文件创建的示例代码,在上传到sharepoint之前。



string mSubject = mItem.Subject;

string targetFileURL = targetFolderUrl +/+ Regex.Replace(mSubject,@[^ \\\\。@ - ],,RegexOptions.None,TimeSpan.FromSeconds(1.5));



//将URL限制为150个字符

if(targetFileURL.Length> 150)

targetFileURL = targetFileURL.Substring(0,150)+ .eml;

else

targetFileURL = targetFileURL +" .eml";



mItem。加载(新的PropertySet(ItemSchema.MimeContent));

MimeContent mc = mItem.MimeContent;

FileCreationInformation newFile = new FileCreationInformation();

newFile.Content = mc.Content;

newFile.Url = targetFileURL;

newFile.Overwrite = true;





它非常适合.EML格式,但是当我尝试以.MSG格式保存文件时,它会抛出错误。



有关如何以正确的MSG格式保存文件的任何建议?非常感谢快速回复。



谢谢

Hi,

I am working on a solution to to extract emails from exchange using EWS APIs and then upload to SharePoint online . Below is the sample code for file creation, and before upload to sharepoint.

string mSubject = mItem.Subject;
string targetFileURL = targetFolderUrl + "/" + Regex.Replace(mSubject, @"[^\w\.@-]", "", RegexOptions.None, TimeSpan.FromSeconds(1.5));

//limit URL to 150 characters
if (targetFileURL.Length > 150)
targetFileURL = targetFileURL.Substring(0, 150) +".eml";
else
targetFileURL = targetFileURL + ".eml";

mItem.Load(new PropertySet(ItemSchema.MimeContent));
MimeContent mc = mItem.MimeContent;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = mc.Content;
newFile.Url = targetFileURL;
newFile.Overwrite = true;


It works perfectly well for .EML format but when I try to save the file in .MSG format it throws error.

Any suggestions on how to save the file in proper MSG format? Will greatly appreciate quick responses.

Thanks

推荐答案

Outlook可能正在运行且文件是打开供Outlook专用(这是打开文件的默认方式)。



如果这是问题(无论您的访问是否被Outlook或任何其他进程阻止),您都可以使用Sysinternals实用程序handle.exe。有关进一步的细节以及如何调查此类案例的说明,请参阅我过去的答案:

如何压缩错误'它已被vb.net中的另一个进程'使用 [ ^ ]。



如果问题只是权限,请检查权限。然后,您可能需要以管理员身份运行您的应用程序。 (我怀疑情况确实如此。)



如果你真的需要使用MSG,你需要明白这种格式是专有的,所以很多相关的产品,即使是第三方,也将是商业性的。但您不必使用此类产品,因为该格式在公开发布的出版物中有所描述。请参阅: https://msdn.microsoft.com/en-us/library/cc463912.aspx [ ^ ]。



另见这篇非常受欢迎的CodeProject文章:用C#读取Outlook MSG文件 [ ^ ]。



很抱歉,他的文章仅供阅读,但仍然有用。



参见: http://blogs.msdn.com/b/openspecification/archive/2009/11/06/msg-file-format-part-1.aspx [<一个href =http://blogs.msdn.com/b/openspecification/archive/2009/11/06/msg-file-format-part-1.aspx\"target =_ blank title =新窗口> ^ ]。



-SA
It's possible that Outlook is running and the file is opened for exclusive use by Outlook (this is the default way of opening files).

If this is that problem (no matter if your access is blocked by outlook or any other process), you can use the Sysinternals utility "handle.exe". For further detail and the explanation on how you investigate such case, please see my past answer:
how to compress the error 'it is already used by another process' in vb.net[^].

If the problem is just permission, just check up permission. Then you may need to just run your application as administrator. (I doubt this is the case though.)

If you really need to work with MSG, you need to understand that the format is proprietary, so many relevant products, even 3rd-party ones, will be commercial. But you don't have to use such products, as the format is described in publicly available publications. Please see: https://msdn.microsoft.com/en-us/library/cc463912.aspx[^].

See also this very popular CodeProject article: Reading an Outlook MSG File in C#[^].

Sorry that his article is only for reading, but it still can be helpful.

See also: http://blogs.msdn.com/b/openspecification/archive/2009/11/06/msg-file-format-part-1.aspx[^].

—SA


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆