0

以下行用于检索给定人员(通过电子邮件地址)的直线经理的电子邮件地址:

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
gal = outlook.Session.GetGlobalAddressList()
entries = gal.AddressEntries

chk_email = ['david@company.com']

for chk in chk_email:
    for e in entries:
        user = e.GetExchangeUser()
        if user is not None and chk == user.PrimarySmtpAddress.lower():
            print (user.GetDirectReports())

            # It prints:
            # <win32com.gen_py.Microsoft Outlook 16.0 Object Library.AddressEntries instance at 0x2115795695424>

            # then, added lines but returned nothing
            for recipient in user.GetDirectReports():
                print (recipient)                      # returns nothing
                recipient.Resolve()
                print (recipient.AddressEntry())        # returns nothing
                print (recipient.AddressEntry.Address) # returns nothing
                print (recipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress()) # returns nothing

上述案例大卫有一名直线经理。

我还尝试了另一个,南希,直线经理也是下属。在这一行中,它显示错误:

recipient.Resolve()

AttributeError: '<win32com.gen_py.Microsoft Outlook 16.0 Object Library.AddressEntry instance at 0x2242384456894>' 对象没有属性 'Resolve'

如何获取/解释“xxxx@xxxx.com”表格中的直线经理的电子邮件地址?

我也尝试过user.GetExchangeUserManager(),它返回“<win32com.gen_py.None.ExchangeUser>”。

4

1 回答 1

2

当然——你得到一个 COM 类型的对象AddressEntries。您需要遍历其条目。

并且永远不要遍历 GAL-call Namespace.CreateRecipient/中的所有条目Recipient.Resolve,然后使用Recipient.AddressEntry.

于 2021-02-18T22:43:26.187 回答