You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python将现有联系人添加至Outlook通讯组列表(DL)

使用Python向Outlook通讯组列表(DL)添加成员

要实现向现有通讯组添加成员,核心是获取目标通讯组的ExchangeDistributionList对象,再调用它的AddMember方法添加指定联系人。以下是结合你现有代码的完整实现:

import win32com.client

outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
address_lists = outlook.AddressLists
gal = address_lists['Global Address List']

# 获取目标通讯组 "DL Data" 并转换为可操作的ExchangeDistributionList对象
dl_entry = gal.AddressEntries.Item('DL Data')
dl = dl_entry.GetExchangeDistributionList()

# 定义要添加的联系人邮箱
target_email = "test1@company.com"

# 在全局地址列表中查找对应联系人的AddressEntry
contact_entry = None
for entry in gal.AddressEntries:
    try:
        ex_user = entry.GetExchangeUser()
        if ex_user and ex_user.PrimarySmtpAddress.lower() == target_email.lower():
            contact_entry = entry
            break
    except:
        # 跳过非Exchange用户条目(如其他通讯组)
        continue

# 执行添加操作
if contact_entry:
    dl.AddMember(contact_entry)
    print(f"已成功将 {target_email} 添加到通讯组")
else:
    print(f"未找到邮箱为 {target_email} 的联系人")

注意事项

  • 需确保你的Outlook账户拥有该通讯组的修改权限,否则会抛出权限错误
  • 代码中通过try-except跳过非Exchange用户条目,避免处理无效条目时崩溃
  • 若需批量添加,可将目标邮箱存入列表,循环执行查找和添加逻辑

内容的提问来源于stack exchange,提问作者samronaldo309

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 20:21:42