Get SenderEmailAddress from mail item in compose mode

1k views Asked by At

I am retrieving, this mailItem in compose mode, But when I check for the mailItem.SenderEmailAddress, it is NULL, but all other properties have values there (Ex:- body, body format, to, .... ). How I get the sender email FROM THE MAIL-ITEM IT-SELF?

I am using Visual Studio 2013 with Addin express v.7.7.4087

Here is the code :-

        Outlook.Inspector currentInspector = null;
        Outlook.MailItem mailItem = null;
        Outlook.Folder outboxFolder = null;
        Outlook.Recipients recipients = null;

        const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

        currentInspector = Globals.ObjOutlook.ActiveInspector();

        if (currentInspector != null)
            {

            if (currentInspector.CurrentItem is Outlook.MailItem)
            {
                mailItem = currentInspector.CurrentItem as Outlook.MailItem;
                mailItem.Save();
                string sender = mailItem.SenderEmailAddress; //This is null 
            }
        }

P.S I have to deal with multiple mail boxes. so, I can't get current users address using Namespace. It always return me the address of primary mail box user.

Please see following screen shot enter image description here

Thanks in advance.

Kushan Randima

2

There are 2 answers

3
Dmitry Streblechenko On BEST ANSWER

Are you sending using multiple Exchange accounts? Use MailItem.SendUsingAccount, then read Account.SmtpAddress. If it is "", use Account.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress.

If MailItem.SendUsingAccount == null, you can assume the default account.

2
Eugene Astafiev On

Use the CurrentUser property of the Namespace class to get the currently logged-on user as a Recipient object. The Address property of the Recipient class returns a string representing the e-mail address of the Recipient.