Outlook caches the email address once an email is sent and shows suggestions the next time I try to enter in the TO field. The contact card also shows the cached email address from exchange.
I am unable to retrieve this email address in code when outlook is in Direct mode(olCachedOffline i.e. "Use Cached Exchange Mode" option is unchecked in Outlook Mail Settings) , code is throwing the exception "The property "http://schemas.microsoft.com/mapi/proptag/0x800F101E" is unknown or cannot be found." tried for both Schema urls at the lines addressEntry.PropertyAccessor.GetProperty().
This is the code I am using. It works fine in Cached mode (Online).
private string GetExchangeEmail(Outlook.AddressEntry addressEntry)
{
Outlook.ExchangeUser user = addressEntry.GetExchangeUser();
string emailAddress = user.PrimarySmtpAddress;
// return from here if emailAddress is valid
string schemaName = string.Empty;
Outlook.OlExchangeConnectionMode connectionMode = Globals.AddIn.Application.Session.ExchangeConnectionMode;
if (connectionMode == Outlook.OlExchangeConnectionMode.olCachedConnectedDrizzle ||
connectionMode == Outlook.OlExchangeConnectionMode.olCachedConnectedFull ||
connectionMode == Outlook.OlExchangeConnectionMode.olCachedConnectedHeaders ||
connectionMode == Outlook.OlExchangeConnectionMode.olCachedDisconnected ||
connectionMode == Outlook.OlExchangeConnectionMode.olCachedOffline)
{
// For Direct Mode
// PR_SMTP_ADDRESS = 0x39FE001E;
string FinalEmail = addressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E") as string;
return FinalEmail.Replace("SMTP:", "");
}
else
{
// For Cached Mode
// PR_EMS_AB_PROXY_ADDRESSES = 0x800F101E;
string FinalEmail = addressEntry.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x800F101E") as string;
return FinalEmail.Replace("SMTP:", "");
}
}