以下行用于检索给定人员(通过电子邮件地址)的直线经理的电子邮件地址:
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>”。