c# - 将 MailItem 转换为内存中的 MSG,而不是文件系统中的 MSG

标签 c# .net outlook ms-office msg

目前,我通过将 mailItem 写入 MSG 文件来对 mailItem 进行 base64 编码:

 mailItem.SaveAs(@"c:\path\to\save\mail.msg", Outlook.OlSaveAsType.olMSG);
 FileStream fs = new FileStream( fullPath, FileMode.Open, FileAccess.Read );
 byte[] filebytes = new byte[fs.Length];
 fs.Read( filebytes, 0, Convert.ToInt32( fs.Length ) );
 string encodedData = Convert.ToBase64String( filebytes, 
 Base64FormattingOptions.InsertLineBreaks );

我经过长时间的努力,没有找到一种方法可以在不将 MSG 写入硬盘的情况下执行此操作。

有没有办法可以在不需要写入硬盘的情况下执行此操作?

谢谢!

最佳答案

Justin Cooney (强调他的):

The Outlook.MailItem object is in fact a COM object that cannot be dynamically saved/loaded. To achieve the desired save/load functionality the Outlook.MailItem object will first need to be converted to a .MSG file.

这也是我想做的事情,但可惜由于上述限制而无法实现。我当前正在将文件写入临时位置、传递路径、转换为 Base64 字符串并在成功后删除文件。

关于c# - 将 MailItem 转换为内存中的 MSG,而不是文件系统中的 MSG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44435985/

相关文章:

excel - OneDrive 中的文件未附加到 Outlook 消息 : Download error

c# - ASP.NET Core 测试 - 在夹具中初始化 InMemory SQLite dbcontext 时获取 NullReferenceException

C#清除已关闭应用程序的托盘图标

c# - 糟糕设计的空抽象类/接口(interface)标志?

c# - 如何测量文件(硬盘)I/O 的特性?

vba - 如何向可能重定向到登录页面的页面发出 POST 请求

c# - SQL Server 2008——并行执行查询

c# - WatiN.Core.IE 组件在打开 URL 时出现 Internet Explorer 忙时超时错误

c# - 数组、数组列表还是列表列表?

PHP 使用 Outlook 发送邮件