1

我使用了 win32.client 并且可以使用 python 成功访问交换分发列表的成员。但是,由于有两个用户的名字和姓氏相同,我希望能够访问他们的电子邮件地址而不是名字。

使用下面的循环,我可以浏览 Exchange Distribution List 的成员并打印所有成员的名称:

import win32com.client

outlook_obj = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") 

#This function gets outlook object and retuens all the members of ALL Groups
address_lists = outlook_obj.AddressLists

#Access Exchange Distribution Lists
dist_lists = address_lists['All Distribution Lists']
return(dist_lists)

dl_index = a_numerical_index_greater_than_zero # you can try different numbers until you find the index of your desired distributionList, or loop thorough all the members and find what you are looking for
for m in dist_lists.AddressEntries.Item(dl_index).GetExchangeDistributionList().Members:
    print(str(m))

上面的脚本完美地工作并打印出分发列表中所有成员的所有名称。但是,我正在寻找成员的不同电子邮件地址,因为我看到名字并不不同(我可以有两个同名的人 Jack Smith,但 jack.smith@xyz.com 和 jack.smith2@xyz.com 是仍然明显)。

我使用源中的对象定义来构建上述代码,但似乎我无法将成员连接到他们的电子邮件地址。

感谢任何帮助!

4

1 回答 1

1

好的 - 我得到了我的答案,我正在分享以防其他人可能需要这个。

确实,下面的脚本正在返回成员的地址条目

dist_lists.AddressEntries.Item(dl_index).GetExchangeDistributionList().Members[0].GetExchangeUser()

和 addressEntry 可以让您访问帐户的所有详细信息,包括电子邮件地址。以下是获取用户电子邮件地址的确切代码

dist_lists.AddressEntries.Item(dl_index).GetExchangeDistributionList().Members[0].GetExchangeUser().PrimarySmtpAddress
于 2020-04-15T04:52:47.803 回答