如何在Outlook中访问撰写邮件项目的主题

时间:2010-06-16 17:50:46

标签: c# visual-studio-2008 outlook-2007 outlook-object-model

在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为空。

2 个答案:

答案 0 :(得分:1)

这就是我想要的:

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

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

在保存邮件项目之前,主题为空,无论是因为它已发送还是作为草稿。我们可以通过编程方式保存它,然后获得主题。

另一个注意事项:如果主题在保存时为空白,则仍会显示为空。

答案 1 :(得分:-1)

CurrentItem用于当前的电子邮件项目。

您需要创建一个新的。

Outlook.MailItem mic = (Outlook.MailItem)(application.CreateItem(Outlook.OlItemType.olMailItem));