Get Smtp email from ContactInfo stored in Exchange

2020-03-26 13:33发布

I am using VSTO for my Outlook add-in. Currently I am processing email addresses from all Outlook contacts. There is no problem for instances of ContactInfo if EmailAddress1Type is "SMTP".

But how to get email address for Exchange contact (Email1AddressType = "EX")?

Redemption library is not solution for me as it is expensive just to solve this one problem.

Thank you in advance,

Dusan

1条回答
贪生不怕死
2楼-- · 2020-03-26 14:05

Here is the MSDN reference link and corresponding sample code:

private const string Email1EntryIdPropertyAccessor = "http://schemas.microsoft.com/mapi/id/{00062004-0000-0000-C000-000000000046}/80850102";

PropertyAccessor propertyAccessor = contactItem.PropertyAccessor;
object rawPropertyValue = propertyAccessor.GetProperty(Email1EntryIdPropertyAccessor);
string recipientEntryID = propertyAccessor.BinaryToString(rawPropertyValue);
Recipient recipient = contactItem.Application.Session.GetRecipientFromID(recipientEntryID);
if (null == recipient)
    throw new InvalidOperationException();

bool wasResolved = recipient.Resolve();
if (!wasResolved)
    throw new InvalidOperationException();
ExchangeUser exchangeUser = recipient.AddressEntry.GetExchangeUser();
string smtpAddress = exchangeUser.PrimarySmtpAddress;
查看更多
登录 后发表回答