4

I am trying to get the SMTP Address for an email and I have written a code to avoid getting the x.500 address. I get the SMTP address by accessing PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) where PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

However, this works on some laptops while some give an error saying

"The property http://schemas.microsoft.com/mapi/proptag/0x39FE001E is unknown or cannot be found."

Any idea how to resolve this?

1 Answer 1

2

If you want the SMTP address, you can create an Outlook.Recipient from the X.500 and resolve the Recipient.AddressEntry to an Outlook.ExchangeUser.

string address = string.Empty;
Outlook.Recipient recipient = mailItem.Application.Session.CreateRecipient(mailItem.SenderEmailAddress);
if (recipient != null && recipient.Resolve() && recipient.AddressEntry != null) 
{
    Outlook.ExchangeUser exUser = recipient.AddressEntry.GetExchangeUser();
    if (exUser != null && !string.IsNullOrEmpty(exUser.PrimarySmtpAddress))
      address = exUser.PrimarySmtpAddress;
}

The error you are receiving with PR_SMTP_ADDRESS indicates that the MIME property isn't present in the mail message properties and you need an alternate means to determine the senders SMTP address. You cannot assume a MIME property will always be present.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks SilverNinja, what property should I access to get the email address for each of the other scenarios in the if statements.
I used the above code and it works on some outlook accounts but not on others. For the accounts it does not work, the recipient.resolve() comes as false. Not sure why. I checked the email address and it shows in x.500 format and I followed the code above to convert it to primarysmtpaddress but it fails at recipient.resolve().
Does Check Names work for the username? Recipient.Resolve just resolves the recipient against the users address book. If it cannot be resolved, an AddressEntry will not be found. As a fallback, you can check if the property PidLidInternetAccountName exists.
When you say as a fallback, should I check PidLidInternetAccountName property in the else statement for the outer if in the code above? If that's true, how should I proceed with getting the primarysmtpaddress? The same way as explained above?
I get it now when you say fallback. So if PidLidInternetAccountName specifies the user-visible email account name through which the email is sent, why dont we just use this property rather than going through the code that you mentioned above?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.