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

问题描述 投票:0回答:1

我使用win32.client,可以使用python成功访问交换通讯组列表的成员。但是,因为有两个用户的名字和姓氏相同,所以我希望能够访问其电子邮件地址而不是名称。

使用下面的循环,我可以浏览Exchange通讯组列表的成员并打印所有成员的名称:

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,但是[email protected][email protected]是仍然不同)。

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

感谢任何帮助!

python exchange-server win32com distribution-list
1个回答
0
投票

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

实际上是下面的脚本正在返回成员的addressEntry

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

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

dist_lists.AddressEntries.Item(dl_index).GetExchangeDistributionList().Members[0].GetExchangeUser().PrimarySmtpAddress
© www.soinside.com 2019 - 2024. All rights reserved.