2016-02-09 15 views
0

我發送一封HTML格式的HTML(MIME)郵件給我的電子郵件帳戶,現在我正在步行穿過sample VSTO program。我點擊了特定的電子郵件。展望VSTO:MailItem不包含`HTMLBody`的定義

我在這裏的代碼:

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?) 

我不明白爲什麼我得到錯誤。

回答

0

嘗試使用後期綁定技術(請參見.Net中的Type.InvokeMember)訪問該屬性。

你是否在輔助線程上運行代碼?你使用什麼事件處理程序來訪問主體?

無論如何,Outlook對象模型不會爲簽名提供anythyng。但是,您可以使用VBA宏在運行時編輯郵件正文。

Outlook對象模型提供了與項目機構合作方式主要有三種:

  1. Body - 代表Outlook項目的明文體的字符串。
  2. HTMLBody - 表示指定項目的HTML正文的字符串。
  3. Word editor - 正在顯示的消息的Microsoft Word文檔對象模型。 Inspector類的WordEditor屬性返回Word對象模型中的Document類的實例,您可以使用該對象設置消息正文。

您可以在Chapter 17: Working with Item Bodies中閱讀更多關於所有這些方法。我們決定以哪種方式選擇處理郵件正文。

相關問題