简体   繁体   中英

How to retrieve the sender smtp email address with Outlook interop?

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 username@abc.com 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM