0

I want to search for an addressEntry object in global address list using below code in C#.

Microsoft.Office.Interop.Outlook.Application app = new Outlook.Application();
Outlook.AddressList gal = app.Session.GetGlobalAddressList();
Outlook.AddressEntry entry = gal.AddressEntries[name];

But i got the 1st matched name which is not correct. I want to pass alias or primarySMTPAddress(mailId) as index which is unique. Give me the method to pass unique value to get exact addressEntry Object. Else method to fetch all the matching addressEntry objects.

And you can suggest the possible index parameters for below snippet.

Outlook.AddressEntry entry = gal.AddressEntries[name];
  • possible duplicate of [Collection of AddressEntry object from Global Address List MSDN](http://stackoverflow.com/questions/28831640/collection-of-addressentry-object-from-global-address-list-msdn) – Eugene Astafiev Mar 04 '15 at 12:27

1 Answers1

-1

You need to iterate over all items to find the exact match. The Outlook object model doesn't provide any method or property for that.

Using a low-level code (Extended MAPI) as Dmitry suggested you can create a RES_PROPERTY restriction on PR_ANR and call IMAPITable::Restrict on the contents table of the corresponding IABContainer object. This is the same restriction used by Outlook when it resolves a name against a particular container and shows an ambiguous name dialog.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45