[英]Save 'MailItem' object as .msg file
Following from the code outlined here 遵循此处概述的代码
How can I save the MailItem
object as a .msg
file? 如何将
MailItem
对象保存为.msg
文件?
Or another way to put this is: How can I create a .msg
file using the attributes(sender, cc, bcc, subject, body, etc.) of a MailItem
object? 或者另外一种方法是:如何使用
MailItem
对象的属性(sender,cc,bcc,subject,body等)创建.msg
文件?
mailItem.SaveAs(savepath);
Where mailItem is the Outlook MailItem and the savepath is for instance: 其中mailItem是Outlook MailItem,例如savepath:
String savepath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + filename + ".msg";
If you wish to use the MailItem subject as the filename you might want to remove invalid chars for filenames: 如果您希望将MailItem主题用作文件名,则可能需要删除文件名的无效字符:
String filename = mailItem.Subject;
string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
foreach (char c in invalid)
{
filename = filename.Replace(c.ToString(), "");
}
Use MailItem.SaveAs(..., olMsg) - see http://msdn.microsoft.com/en-us/library/office/bb175283(v=office.12).aspx . 使用MailItem.SaveAs(...,olMsg) - 请参阅http://msdn.microsoft.com/en-us/library/office/bb175283(v=office.12).aspx 。
Or do you mean you want to create an MSG file from the scratch without an actual MailItem object living in one of the Outlook folders? 或者你的意思是你想从头开始创建一个MSG文件,而没有一个实际的MailItem对象存在于其中一个Outlook文件夹中? In that case you can use Redemption and its RDOSession.CreateMessageFromMsgFile method (returns RDOMail object).
在这种情况下,您可以使用Redemption及其RDOSession.CreateMessageFromMsgFile方法(返回RDOMail对象)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.