【问题标题】:How to return department information from outlook contacts如何从 Outlook 联系人返回部门信息
【发布时间】:2018-07-13 15:11:05
【问题描述】:

我正在尝试使用 python 在 GAL 上查找 Outlook 联系人并返回他们的部门信息(与他们在系统中的 Outlook 帐户相关联)。我可以访问联系人列表并根据姓名进行搜索,但找不到返回部门的方法。是否有可能通过 python 访问该信息?

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

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

nameAliasDict = {}

for i in contacts:
    Name = i.Name
    x = ?   #Not sure what to make x equal to in order to make it department information
    if Name == 'FirstN LastN':
        print(x)

我知道部门信息已附加到 Outlook 联系人,因为每当我尝试向某人发送电子邮件并搜索他们的姓名时,它都会显示在表格中。

【问题讨论】:

  • 您应该通过查看object.__dict__ 来查看所提供的属性类型。即,如果您没有找到解决方案,请print("adrLi has: ", adrLi.__dict__); print("contacts has: ", contacts.__dict__); 并在此处发布结果。
  • @musikreck 这就是我得到的:联系人有:{'oleobj': } ========= === RESTART: H:/SecondRotation/python/access outlook.py ============ adrList has: {'oleobj': }
  • 呸。不好意思问了,哈哈。可以for i in ns.AddressLists: print(i)吗?
  • @musikreck 我将这两行连续打印了 5 次:
  • 好的,我似乎无法安装win32com 模块来自己测试这个。但它看起来确实像Department 属性存在。见here。

标签: python outlook


【解决方案1】:

不要遍历地址簿容器中的所有条目 - 一些 GAL 容器可以包含 100,000 多个条目。使用Namespace.CreateRecipient / Recipient.Resolve。这与在 Outlook 的“收件人”编辑框中键入名称并按 Ctrl+K 解决它的效果相同。获得已解析的 Recipient 对象后,调用 Recipient.AddressEntry.GetExchangeUser().Department. 准备处理错误和 AddressEntry.GetExchangeUser() 返回 null。

【讨论】:

    猜你喜欢
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-10
    • 2012-07-29
    • 1970-01-01
    相关资源
    最近更新 更多