python - 如何从 Outlook 联系人返回部门信息
问题描述
我正在尝试使用 python 在 GAL 上查找 Outlook 联系人并返回他们的部门信息(与系统中的 Outlook 帐户相关联)。我可以访问联系人列表并根据姓名进行搜索,但找不到返回部门的方法。是否可以通过 python 访问该信息?
import win32com.client
o = win32com.client.gencache.EnsureDispatch("Outlook.Application")
ns = o.GetNamespace("MAPI")
adrLi = ns.AddressLists.Item("Global Address List")
contacts = adrLi.AddressEntries
nameAliasDict = {}
for i in contacts:
Name = i.Name
x = ? #Not sure what to make x equal to in order to make it department information
if Name == 'FirstN LastN':
print(x)
我知道部门信息已附加到 Outlook 联系人,因为每当我尝试向某人发送电子邮件并搜索他们的姓名时,它都会显示在表格中。
解决方案
不要遍历地址簿容器中的所有条目 - 一些 GAL 容器可以包含 100,000 多个条目。使用Namespace.CreateRecipient
/ Recipient.Resolve
。这与在 Outlook 的“收件人”编辑框中键入名称并按 Ctrl+K 解决它的效果相同。获得已解析的收件人对象后,调用Recipient.AddressEntry.GetExchangeUser().Department.
准备处理错误并AddressEntry.GetExchangeUser()
返回 null。
推荐阅读
- angular - 不使用构造函数注入服务
- python - Python 3用例继续而不是不(!=)
- javascript - 无法使用 webpack 在 GitHub Actions 中构建生产环境
- reporting-services - 自上次在 SSRS 中执行以来查询已更改
- php - 如何在 Laravel 中连接两个表
- java - Java 和 Python 合并排序
- javascript - Webpack 不会用 background-image 编译我的 SASS
- python - 类型错误:create_superuser() 缺少 2 个必需的位置参数:“first_name”和“last_name”
- assembly - Nasm - 程序如何跟踪哪个寄存器存储了负值或正值
- javascript - 作为本练习的解决方案,这两个循环之间的主要区别是什么?(学习javascript)