【发布时间】:2015-08-25 01:16:51
【问题描述】:
有一些关于此的 Stackoverflow 问题,但没有一个真正提供解决方案。
场景 - 我正在 VS2013 中创建 Outlook 插件。用户选择电子邮件,点击我的 AddIn 按钮,电子邮件被发送到 Web 服务以存储在数据库中并链接到客户端。任何位置的任何人都可以打开电子邮件进行查看。
目前我正在使用MailItem.SaveAs(filePath)函数,然后使用File.ReadAllBytes(filePath)创建一个可以发送到webservice的字节数组。
我一创建字节[]就删除文件:
for (int x = 0; x < Emails.Count; x++)
{
//TODO: RMc - is there a better way than saving to disk? unable to convert MailItem directly to stream...!
Guid g = Guid.NewGuid();
string filePath = "c:\\temp\\" + g.ToString() + ".msg";
Emails.ElementAt(x).SaveAs(filePath);
byte[] by = File.ReadAllBytes(filePath);
File.Delete(filePath);//no longer needed now we have byte array
//this is where I create a list of objects with all required data to send to web service
}
将文件写入磁盘很慢 - 它会创建一个 *.msg 文件,如果没有人想查看它,它可能永远不会真正被使用。因此,我希望能够将 MailItem 对象直接保存到字节数组中 - 然后我可以将其保存到数据库中,并且仅在用户需要时才创建 *.msg 文件。
MailItem 对象看起来是动态的,所以我认为这是问题所在。
谁能提供实现我所描述的解决方案或替代方法?
【问题讨论】:
-
字节数组必须是MSG格式吗?
-
嗨,最好是 MailItem 的字节数组。