Search code examples
c#outlookadd-in

outlook vsto perform custom send message


I have an Outlook add-in that adds a custom Send button to the NewMailMessage tab in the Compose inspector window. When clicking on this custom button I want to perform some modifications to the email being sent before actually sending it out. How do I get a hold of the email from the button click event? In older versions than Outlook 2010, I know you can programmatically get the "Send" CommandBar button and call Execute on it to mimic sending the message. However in 2010 and later versions this method has been deprecated. MSDN suggests to implement the IRibbonExtensibility for Ribbon customizations but do I need to do that for my purpose?


Solution

  • I found an answer:

    if (this.Context is Outlook.Inspector)
    {
        Outlook.Inspector oInsp = this.Context as Outlook.Inspector;
        if (oInsp.CurrentItem is Outlook.MailItem)
        {
            Outlook.MailItem oMail = oInsp.CurrentItem as Outlook.MailItem;
            ((Outlook._MailItem)oMail).Send();
        }
    }