【问题标题】:Create outlook .msg file in C#在 C# 中创建 Outlook .msg 文件
【发布时间】: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


【解决方案1】:

在您执行此操作的计算机上是否已安装 Outlook 并处于可运行状态?错误是 com 组件未注册,这通常意味着您只是从另一台未注册 com 的机器上复制了 dll。

所以要么安装outlook,要么安装这个

https://www.microsoft.com/en-us/download/details.aspx?id=1004

【讨论】:

  • 我安装了它,没有任何改变。抛出同样的错误。
  • @Neha 您能否详细说明以下内容 - 运行机器的每个操作系统的 64 与 x86、office DLL 以及 VS 构建设置的内容?
【解决方案2】:

两种方法都会给你同样的错误?如果 Redemption 无法定位和加载 MAPI 系统,则返回 0x8004010F (MAPI_E_NOT_FOUND)。

确保已安装 Outlook,并且您的应用的位数与 Outlook 的位数相匹配(请参阅http://www.dimastr.com/redemption/faq.htm#ErrorCreatingRedemptionObject)。如果无法安装 Outlook,您可以从 https://www.microsoft.com/en-us/download/details.aspx?id=42040 安装独立版本的 MAPI,但请注意它不支持 Unicode MSG 文件。

【讨论】:

    【解决方案3】:

    我在我的系统上安装了 Outlook。我在上面发布的代码 (Microsoft.Office.Interop.Outlook.Application) 就像一个魅力 :)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2014-12-25
      • 1970-01-01
      • 2016-11-19
      相关资源
      最近更新 更多