Outlook VSTO:MailItem不包含`HTMLBody`的定义

时间:2016-02-09 23:46:26

标签: vsto outlook-addin

我将带有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?)

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

1 个答案:

答案 0 :(得分:0)

Try to use the late binding technology (see Type.InvokeMember in .Net) for accessing the property.

Do you run the code on a secondary thread? What event handler do you use for accessing the body?

Anyway, the Outlook object model doesn't provide anythyng for signatures. But you can edit the message body at runtime using VBA macros.

The Outlook object model provides three main ways for working with item bodies:

  1. Body - a string representing the clear-text body of the Outlook item.
  2. HTMLBody - a string representing the HTML body of the specified item.
  3. Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.

You can read more about all these ways in the Chapter 17: Working with Item Bodies. It us up to you which way is to choose to deal with the message body.