在 C# 中创建 outlook .msg 文件
Create outlook .msg file in C#
我正在尝试使用我的 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): 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。仍然没有解决我的问题。
您执行此操作的机器上是否安装了 outlook 并且处于可运行状态?错误是 com 组件没有注册,这通常意味着你只是从另一台没有注册 com 的机器上复制 dll。
所以要么安装 outlook,要么安装这个
https://www.microsoft.com/en-us/download/details.aspx?id=1004
我在我的系统上安装了 Outlook。我在上面发布的代码 (Microsoft.Office.Interop.Outlook.Application) 很有魅力 :) .
我正在尝试使用我的 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): 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。仍然没有解决我的问题。
您执行此操作的机器上是否安装了 outlook 并且处于可运行状态?错误是 com 组件没有注册,这通常意味着你只是从另一台没有注册 com 的机器上复制 dll。
所以要么安装 outlook,要么安装这个
https://www.microsoft.com/en-us/download/details.aspx?id=1004
我在我的系统上安装了 Outlook。我在上面发布的代码 (Microsoft.Office.Interop.Outlook.Application) 很有魅力 :) .