Getting contact information from the Outlook GAL using Python and win32com

6k Views Asked by At

I am trying to write a script in Python that will pull the contact information from the Outlook Global Address List. For each entry, I've managed to get the name of the contact, as well as the alias (with some additional parsing).

My code is posted below:

import win32com.client

o = win32com.client.gencache.EnsureDispatch("Outlook.Application")
ns = o.GetNamespace("MAPI")

adrLi = ns.AddressLists.Item("Global Address List")
contacts = adrLi.AddressEntries
numEntries = adrLi.AddressEntries.Count

nameAliasDict = {}

for i in contacts:
    name = i.Name
    alias = i.Address.split("=")[-1]
    nameAliasDict[alias] = name

print "\nThe global address list contains",numEntries,"entries."

Is there a way I can get the full set of information that shows up when I open the GAL in Outlook (such as Title, Email Address)?

Thanks.

1

There are 1 best solutions below

0
On

Use AddressEntry.GetExchangeUser to retrieve the ExchangeUser object. If some MAPI property is not explicitly exposed by the ExchangeUser object, you can retrieve it using AddressEnttry.PropertyAccessor.GetProperty. Take a look at the GAL address entries with OutlookSpy (I am its author) - click IAddrBook | Open Root Container or IMAPISession | QueryIdentity to see GAL objects and their MAPI properties.