2010-06-16 110 views
1

在Outlook中,我可以設置新郵件的主題(撰寫新郵件消息時),但是我想預先添加文本。所以我需要先獲得主題,然後設置它。如何在Outlook中訪問撰寫郵件項目的主題

Outlook.Application application = Globals.ThisAddIn.Application; 
Outlook.Inspector inspector = application.ActiveInspector(); 
Outlook.MailItem myMailItem = (Outlook.MailItem)inspector.CurrentItem; 

if (myMailItem != null && !string.IsNullOrEmpty(myMailItem.Subject)) 
{ 
    myMailItem.Subject = "Following up on your order"; 
} 

此代碼適用於答覆,但不適用於新消息,因爲在這種情況下,myMailItem爲空。

回答

1

這就是我一直在尋找:

if (thisMailItem != null) 
{ 
    thisMailItem.Save(); 

    if (thisMailItem.EntryID != null) 
    { 
     thisMailItem.Subject = "prepended text: " + thisMailItem.Subject; 
     thisMailItem.Send(); 
    } 
} 

主題爲空,直到郵件項目已經被保存,可能是因爲它被髮送,或者爲草稿。我們可以以編程方式保存它,然後獲取主題。

另一個注意事項:如果在保存時主題爲空白,它仍然顯示爲空。

0

CurrentItem用於當前電子郵件項目。

您需要創建一個新的。

Outlook.MailItem mic = (Outlook.MailItem)(application.CreateItem(Outlook.OlItemType.olMailItem)); 
相關問題