获取Exchange通讯组列表成员的电子邮件地址-Python



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

使用下面的循环,我可以浏览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仍然是不同的(。

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

感谢您的帮助!

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

事实上,下面的脚本正在返回成员的addressEntry

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

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

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

相关内容

最新更新