我想用我的C#代码创建outlook .msg格式文件。 我已经使用下面2代码:在C#中创建outlook .msg文件
方法1:
Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.Application();
// Creating a new Outlook message from the Outlook Application instance
Microsoft.Office.Interop.Outlook.MailItem msgInterop = (Microsoft.Office.Interop.Outlook.MailItem)(objOutlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem));
// Set recipient information
msgInterop.To = "[email protected]";
msgInterop.CC = "[email protected]";
// Set the message subject
msgInterop.Subject = "Subject";
// Set some HTML text in the HTML body
msgInterop.HTMLBody = "<h3>HTML Heading 3</h3> <u>This is underlined text</u>";
// Save the MSG file in local disk
string strMsg = @"c:\\temp\TestInterop.msg";
msgInterop.SaveAs(strMsg, Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG);
第二种方法:
Redemption.RDOSession Session = new RDOSession();
Redemption.RDOMail Msg = Session.CreateMessageFromMsgFile(@"c:\temp\YourMsgFile.msg");
Msg.Sent = true;
Msg.Subject = "test";
Msg.Body = "test body";
Msg.Recipients.AddEx("the user", "[email protected]", "SMTP", rdoMailRecipientType.olTo);
Msg.Save();
两种方法给出了关于如下执行错误:
System.Runtime.InteropServices.COMException (0x8004010F): Creating an instance of the COM component with CLSID {29AB7A12-B531-450E-8F7A-EA94C2F3C05F} from the IClassFactory failed due to the following error: 8004010f Exception from HRESULT: 0x8004010F.
我已经研究并发现与平台有一些兼容性问题。我试图将平台从32位更改为x64。仍然没有解决我的问题。
我推荐使用.Net MailMessage内置功能将消息保存为[此处介绍](http://stackoverflow.com/questions/1264672/how-to-save-mailmessage-object-to-disk-as -eml-or-msg-file) – Esko
MailMessage不允许创建我自己的示例电子邮件。当我尝试设置为To时,它表示它是只读变量。 – Neha
你是什么样的电子邮件样本?由于它是一个列表,所以属性是只读的,你需要做message.To.Add(...) – Esko