2
votes

I'm using c# and Microsoft Outlook interop outlook dll to read and retrieve mails from Outlook (Exchange).

I'm facing issues in parsing the sender email address as the code returns the Exchange address rather than the plain email id. What i want to retrieve is like [email protected] but the output of my code is the Exchange address of the email:

(/O=EXCHANGELABS/OU=EXCHANGE ADMINISTRATIVE GROUP (xxxxxxxxxxx)/CN=RECIPIENTS/CN=XXXXXXX32AD740E69184DC03B2A406F4-XXX XXX)

Code I have tried:

emailItem.Sender

and

emailItem.SenderEmailAddress

How do I convert the Exchange address to an smtp address or how do I retrieve just the smtp address?

1

1 Answers

3
votes

This code should do it:

string senderEmailAddress;

if (mi.SenderEmailType == "EX")
{
    senderEmailAddress = emailItem.Sender.GetExchangeUser().PrimarySmtpAddress;                    
}
else
{
    senderEmailAddress = emailItem.SenderEmailAddress;
}

Where:

This should work with Outlook 2010 and newer.