VSTO邮件发送事件

时间:2011-11-13 17:08:09

标签: c# outlook vsto

我对VSTO有一个小问题。我需要收到已发送的邮件并保留其内容。 MailSent活动有没有?

我现在找到的唯一解决方案是在SentItems文件夹上挂起ItemAdd事件。

Outlook.Folder sentItems =
                Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
                as Outlook.Folder;
sentItems.Items.ItemAdd += new ItemsEvents_ItemAddEventHandler(SentItemFolder_ItemAdd);

private void SentItemFolder_ItemAdd(object addedItem)
        {
            Outlook.MailItem newItem = (Outlook.MailItem)addedItem;

            MessageBox.Show(newItem.EntryID);
        }

这真的是唯一的方式,还是你们中任何人都知道更优雅的解决方案?

由于

1 个答案:

答案 0 :(得分:1)

您可以使用ItemSend事件,如下所示:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    this.Application.ItemSend += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
}


private void Application_ItemSend(object Item, ref bool Cancel)
{
    // Code to run when item is being sent
}