我使用了 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 是仍然明显)。
我使用此源中的对象定义来构建上述代码,但似乎我无法将成员连接到他们的电子邮件地址。
感谢任何帮助!