2010-06-16 63 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)); 
相关问题