简体   繁体   中英

How to get email address in Direct Mode(olCachedOffline) for exchange users?

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 ie "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:", "");
    }
}

The solution is to turn on the online mode or switch to the cached mode.

Outlook caches the email address once an email is sent and shows suggestions the next time I try to enter in the TO field.

Check out the associated content of the Inbox folder. I think there you will find the required entries. You may use any low-level (Extended MAPI) property viewer such as MFCMAPI or OutlookSpy for observing the hidden content.

Also you may find the How to configure how the Offline Address Book is downloaded when you use Outlook in Cached Exchange Mode article helpful.

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