Search code examples
c#outlookoutlook-addin

Outlook - How to access the auto-complete address list


I want to be able to access the auto-complete address list that appears when typing into either the TO,CC or BCC lines within an email. I wish to be able to extract this data similarly to how I access other address lists within Outlook.

Would anyone be able to confirm if this is possible and if so how I could go about doing it.

This is currently how I'm extracting email addresses various other address lists.

foreach (Outlook.AddressEntry item in addressList.AddressEntries)
    {
        using (item.ComDisposable())
           {
               switch (item.AddressEntryUserType)
                   {
                       case Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry:
                       case Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry:
                           var exUser = item.GetExchangeUser();
                           Debug.WriteLine(exUser.PrimarySmtpAddress, "_GetOutlookContacts");
                           yield return new EGContact(exUser.Name, exUser.PrimarySmtpAddress, item.ID);
                           break;

                       case Outlook.OlAddressEntryUserType.olOutlookContactAddressEntry:
                            var contact = item.GetContact();
                            yield return new EGContact(contact.FullName, contact.Email1Address, item.ID);
                            break;

                       case Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry:
                       break;

                       default:
                       break;

                  }
          }
    }

Solution

  • Autocomplete stream is stored as a hidden (associated) message with the message class of "IPM.Configuration.Autocomplete" in the Inbox folder. You can see the data in OutlookSpy (I am its author): go to the Inbox folder, click IMAPIFolder button on the OutlookSpy ribbon, go to the "Associated Contents" tab, locate a message with PR_MESSAGE_CLASS == "IPM.Configuration.Autocomplete", select the PR_ROAMING_BINARYSTREAM property to see its contents.

    You can open that message using the Outlook Object Model (MAPIFolder.GetStorage("IPM.Configuration.Autocomplete", OlStorageIdentifierType.olIdentifyByMessageClass), read the property using PropertyAccessor.GetProperty, then parse it. Note that large autocomplete streams cannot be opened using PropertyAccessor.

    If using Redemption an option (I am also its author), it exposes autocomplete as the RDONicknames collection:

     set Session = CreateObject("Redemption.RDOSession")
     Session.MAPIOBJECT = Application.Session.MAPIOBJECT
     set Nicknames = Session.GetNicknames
     for each NickName in NickNames
         Debug.Print NickName.Name & " - " & NickName.SmtpAddress
     next