【发布时间】:2017-07-06 23:24:59
【问题描述】:
我正在尝试使用我的 C# 代码创建 Outlook .msg 格式文件。 我使用了以下 2 个代码:
方法一:
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 = "neha1@gmail.com";
msgInterop.CC = "neha@gmail.com";
// 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", "user@domain.demo", "SMTP", rdoMailRecipientType.olTo);
Msg.Save();
两种方法在执行时都会出错,如下所示:
System.Runtime.InteropServices.COMException (0x8004010F):创建一个 具有 CLSID 的 COM 组件的实例 IClassFactory 中的 {29AB7A12-B531-450E-8F7A-EA94C2F3C05F} 失败 由于以下错误:来自 HRESULT 的 8004010f 异常: 0x8004010F.
我研究并发现了一些与平台的兼容性问题。我试图将平台从 32 位更改为 x64。仍然没有解决我的问题。
【问题讨论】:
-
我推荐使用.Net MailMessage 内置功能将邮件保存为described here
-
MailMessage 不允许创建我自己的示例电子邮件。当我尝试设置 To 时,它说它是只读变量。
-
示例电子邮件是什么意思? To-property 是只读的,因为它是一个列表,你需要做 message.To.Add(...)
标签: c# office-interop outlook-redemption