Get Smtp email from ContactInfo stored in Exchange

隐身守侯 提交于 2019-12-01 08:54:32

问题


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:


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;


来源:https://stackoverflow.com/questions/3189297/get-smtp-email-from-contactinfo-stored-in-exchange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!