目前,我通过将 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/