Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook : How to get email from Recipient field?

I'm attempting to get the email address typed into the To field of a compose mail window.

I try to get the Address property of a Recipient, which according to VS, should give me the email.

I am instead receiving a string that looks like this:

"/c=US/a=att/p=Microsoft/o=Finance/ou=Purchasing/s=Furthur/g=Joe"

How can I get the email address in the recipient field?

My code so far:

List <string> emails = new List<string>();

if (thisMailItem.Recipients.Count > 0)
{
    foreach (Recipient rec in thisMailItem.Recipients)
    {
        emails.Add(rec.Address);
    }
}
return emails;
like image 899
Cat Avatar asked Feb 18 '11 02:02

Cat


People also ask

How do I view email recipients in Outlook?

In the Sent Items folder, open the message that you sent. In the Reading Pane, view the header section of the message. Tips: If there are more recipients, you'll see the number of recipients and more.

How do I get Outlook to show emails instead of names?

In Outlook, choose File > Account Settings > Account Settings. Select the email account that you want to change, and then choose Change. You can change your name on the Account Settings screen. To change the name that displays when you send email, update the Your name field.


3 Answers

Can you try this ?

emails.Add(rec.AddressEntry.Address);

Reference link

EDIT:

I don't have the right environment to test so I'm just guessing all this, but how about

string email1Address = rec.AddressEntry.GetContact().Email1Address;

or .Email2Adress or .Email3Address

Also there is,

rec.AddressEntry.GetExchangeUser().Address

that you might want to try.

like image 56
Bala R Avatar answered Oct 19 '22 16:10

Bala R


Try this

private string GetSMTPAddressForRecipients(Recipient recip)
        {
            const string PR_SMTP_ADDRESS =
                "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            PropertyAccessor pa = recip.PropertyAccessor;
            string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString();
            return smtpAddress;

        }

This is available on MSDN here

I have used the same way to get email addresses in my application and its working.

like image 32
Akanksha Gaur Avatar answered Oct 19 '22 17:10

Akanksha Gaur


the AddressEntry also has an SMTPAddress property that exposes the primary smtp adress of the user.

like image 41
Noam Gal Avatar answered Oct 19 '22 17:10

Noam Gal