【问题标题】:Get email address of members of an Exchange Distribution List - Python获取 Exchange 分发列表成员的电子邮件地址 - Python
【发布时间】:2020-04-15 12:52:47
【问题描述】:

我使用了 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 是仍然不同)。

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

感谢任何帮助!

【问题讨论】:

    标签: python exchange-server win32com distribution-list


    【解决方案1】:

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

    下面的脚本确实返回了成员的地址条目

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

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

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

    【讨论】:

      猜你喜欢
      • 2019-04-25
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      • 2018-10-27
      • 2011-09-14
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多