10. Exchangelib3.2官方文档 —— 联系人

与操作文件夹相同,获取联系人只需使用.people()方法:

# 移动到联系人文件夹并开始搜索
from exchangelib import Account, DistributionList
from exchangelib.indexed_properties import EmailAddress

a = Account(...)
folder = a.root / 'AllContacts'
for p in folder.people():
    print(p)
for p in folder.people().only('display_name').filter(display_name='john').order_by('display_name'):
    print(p)

# 从GAL文件夹获取指定联系人
gal = a.contacts / 'GAL Contacts'
contact = gal.get(email_addresses=EmailAddress(email='lucas@example.com'))
# 所有使用Gmail的联系人
gmail_contacts = list(gal.filter(email_addresses__contains=EmailAddress(email='gmail.com')))
# 所有Gmail邮件地址
gmail_addresses = [e.email for c in gal.filter(email_addresses__contains=EmailAddress(email='gmail.com'))
                   for e in c.email_addresses]
# 所有邮件地址
all_addresses = [e.email for c in gal.all()
                 for e in c.email_addresses if not isinstance(c, DistributionList)]

联系人有照片和备注字段,但它们不能使用。您可以使用如下方式来添加联系人照片和备注:

from exchangelib import Account, FileAttachment

a = Account(...)
contact = a.contacts.get(given_name='John')
contact.body = 'This is a note'
contact.save(update_fields=['body'])
att = FileAttachment(
    name='ContactPicture.jpg',
    content_type='image/png',
    is_inline=False,
    is_contact_photo=True,
    content=open('john_profile_picture.png', 'rb').read(),
)
contact.attach(att)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值