Search code examples
visual-studio-2010vstooutlook-addinoutlook-2010

which account is selected in "FROM" in VSTO outlook 2010 while sending new email?


I am developing an add-in for outlook 2010 using VSTO (visual studio 2010). I am working with mail items and want to get a new email properties and do some works under some conditions while sending a new email, I could get some properties like subject, body, To , CC, BCC, Category. But I could not get some properties such as "From" , Attachment (have or not), attachment size and name, checked as high importance or not, checked as sensitivity or not, request delivery,request read recipt... and some other properties .... below is the code I used :

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Application.ItemSend+=new Outlook.ApplicationEvents_11_ItemSendEventHandler(Application_ItemSend);
        }
        void Application_ItemSend(object Item, ref bool Cancel)
        {
            Outlook.Recipient recipient = null;
            Outlook.Recipients recipients = null;
            Outlook.MailItem mail = Item as Outlook.MailItem;
            string selectedAccount= ?????
        }

How can I get the latter properties?


Solution

  • Sender name is only set after the message is sent and moved to the Sent Items folder. The earliest you will have access to the sender related properties is when the Items.ItemAdd event fires on the Sent Items folder.

    To access attachments, use the MailItem.Attachments collection.

    Account - use MailItem.SendUsingAccount property.

    What was the problem with the Sensitivity, OriginatorDeliveryReportRequested and ReadReceiptRequested properties?