使用 MAPI 从 GAL 检索电子邮件列表

Using MAPI to retrieve the list of emails from GAL

到目前为止,这是我的代码:

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]
    print i.GetExchangeUser().PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3A56101E")

我正在从 https://msdn.microsoft.com/en-us/library/bb446002.aspx

获取 属性

但由于某些原因,我收到此错误:

pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, u'Microsoft Outlook', u'The property "http://schemas.microsoft.com/mapi/proptag/0x3A550003" is unknown or cannot be found.', None, 0, -2147221233), None)

我做错了吗?

您不能假定 PR_CONTACT_EMAIL_ADDRESSES 或任何其他 MAPI 属性 可用。您的代码必须预期并处理来自 PropertyAccessor.GetProperty 的错误。 检查您是否真的可以在 OutlookSpy 中的那个特定对象上看到 属性(我是它的作者 - 单击 IAddrBook,“打开根容器”等)。

为什么您需要 属性?如果您只需要 SMTP 地址。使用 ExchangeUser.PrimarySmtpAddress.