【问题标题】:Outlook VSTO: MailItem does not contain a definition for `HTMLBody`Outlook VSTO:MailItem 不包含“HTMLBody”的定义
【发布时间】:2016-02-13 04:59:47
【问题描述】:

我向我的电子邮件帐户发送了包含 HTML 表格的 HTML (MIME) 消息,现在我正在浏览 sample VSTO program。我点击了那封特定的电子邮件。

我在代码里:

 using Outlook = Microsoft.Office.Interop.Outlook;
 <snip>  

 currentExplorer = this.Application.ActiveExplorer();
    currentExplorer.SelectionChange += new Outlook
        .ExplorerEvents_10_SelectionChangeEventHandler
        (CurrentExplorer_Event);

 private void CurrentExplorer_Event()
  {
   <snip>
  .
  .
  .
  Object selObject = this.Application.ActiveExplorer().Selection[1];
 if (selObject is Outlook.MailItem)
                    {
                        Outlook.MailItem mailItem =
                            (selObject as Outlook.MailItem);
           BREAKPOINT->     itemMessage = "The item is an e-mail message." +
                            " The subject is " + mailItem.Subject + ".";
                        mailItem.Display(false);
                    }

当我在即时窗口中查看mailItem 时出现错误:

?mailItem.HTMLBody
error CS1061: 'MailItem' does not contain a definition for 'HTMLBody' 
 and no extension method 'HTMLBody' accepting a first argument of 
 type 'MailItem' could be found (are you missing a using directive
 or an     assembly reference?)

我不明白为什么我会收到错误消息。

【问题讨论】:

    标签: vsto outlook-addin


    【解决方案1】:

    尝试使用后期绑定技术(参见 .Net 中的Type.InvokeMember)来访问属性。

    您是否在辅助线程上运行代码?您使用什么事件处理程序来访问正文?

    无论如何,Outlook 对象模型不提供任何签名。但是您可以在运行时使用 VBA 宏编辑消息正文。

    Outlook 对象模型提供了三种处理项目主体的主要方式:

    1. Body - 表示 Outlook 项目的明文正文的字符串。
    2. HTMLBody - 表示指定项的 HTML 正文的字符串。
    3. Word editor - 正在显示的消息的 Microsoft Word 文档对象模型。 Inspector 类的 WordEditor 属性从 Word 对象模型返回 Document 类的一个实例,您可以使用它来设置消息正文。

    您可以在Chapter 17: Working with Item Bodies 中阅读有关所有这些方式的更多信息。选择哪种方式处理邮件正文由您决定。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      • 2018-01-27
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2018-11-04
      相关资源
      最近更新 更多