MaiOM
MaiOM

Reputation: 936

VSTO mail sent event

I have a small problem with VSTO. I need to get the sent mail and persist the content of it. Is there a kind on MailSent event?

The only solution I found for now is hooking up the ItemAdd event on SentItems folder.

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);
}

Is this really the only way or any of you know any more elegant solution?

Upvotes: 0

Views: 4663

Answers (1)

GTG
GTG

Reputation: 4954

You can use the ItemSend event for this, like so:

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
}

Upvotes: 2

Related Questions