How to extract email address from Outlook friendly name cache

Hi guys,

A while ago, somebody wrote a little VBA utility to help us to log CRM events. Whenever a user sends an email to a customer, it logs the fact in our CRM database. This is the programmatic process:

1. Grab the email address from ActiveInspector.CurrentItem.To
2. If it's a valid email address, all well and good. Proceed to Step 8.
3. If not a valid email address (it must be a friendly name, perhaps located in Exchange), look for the address in:

ActiveInspector.CurrentItem.Recipients.Item(1).AddressEntry.GetExchangeUser.PrimarySmtpAddress

4. If it's a valid email address, all well and good. Proceed to Step 8.
5. If not a valid email address (it must be in the user's Contact list), look for the address in:

ActiveInspector.CurrentItem.Recipients.Item(1).AddressEntry.GetContact.Email1Address

6. If it's a valid email address, all well and good. Proceed to Step 8.
7. If not a valid email address, then crash!!!         <<------------------------------------------------- Here's where I'm stuck!

8. Get the CustomerID from the CRM, based on email address.
9. Do a bunch of other stuff (for example, send the email, and log the event in the CRM).

I'm a former Access MVP, and am highly experienced with VBA, but my forte is clearly not Outlook. What I'd like to do is find the email address by looking in the local cache, and make sure I get the actual email address rather than the friendly name. I'm not sure if 'local cache' is the right word; I know Outlook stores frequently used email address in some sort of cache, even if the user has not explicitly stored it as a Contact. I just don't know how to find it. Can anyone point me in the right direction, maybe with a method name?

Also, while mucking about with it, I found the following. Would it be useful in this scenario?

ActiveInspector.CurrentItem.Recipients.Item(1).AddressEntry.GetExchangeDistributionList

Many thanks,
Graham R

April 28th, 2015 2:06am

Hi Graham,

This might help you to figure things out a bit.

The contact cache you are looking for is called the nickname cache, also known as the "autocomplete stream."

The nickname files (.nk2) used by older versions of Outlook (2007 and below).

Outlook 2010 and 2013 does not use the NK2 file; it stores the autocomplete cache in the mailbox or data file and caches the addresses in an autocomplete stream at C:\Users\username\AppData\Local\Microsoft\Outlook\RoamCache. The cache is stored in a file named Stream_Autocomplete_0_[long GUID].dat.

For applications that interact with Outlook 2010 or Outlook 2013, the autocomplete stream is stored as a MAPI property and can be modified using the MAPI or the PropertyAccessor object of the message. The PropertyAccessor object is exposed in the Outlook 2010 or Outlook 2013 object models.

Outlook 2010 or Outlook 2013 reads the autocomplete stream from a message in the Associated Contents table of the Inbox of the mail accounts delivery store. This hidden message has a message class and subject of IPM.Configuration.Autocomplete. The autocomplete stream is stored on this message in the PR_ROAMING_BINARYSTREAM property (PidTagRoamingBinary Canonical Property).

References:

How to import .nk2 files into Outlook 2013

Some Application which can read the Nickname Cache

Interacting with the Autocomplete Stream

Autocomplete Stream

https://msdn.microsoft.com/en-us/library/office/ff625291.aspx

Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 2:42am

Thanks Satyajit, that did the trick. Problem solved. :-)

Might I also refer you to my question about ActiveInspector.CurrentItem.Recipients.Item(1).AddressEntry.GetExchangeDistributionList?

Would this be useful in the overall scenario?

April 28th, 2015 3:23am

Hi Graham,

Sorry, I'm not quite sure about it.

Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 3:51am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics