如何使用exchangelib将电子邮件添加到现有日历条目?

2024-10-02 04:34:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经安排了一个现有的日历事件

我正在尝试向现有事件添加大量电子邮件,但当我运行此功能时,它会添加一个新事件

我需要能够:找到活动,将指定的电子邮件添加到活动中,添加电子邮件以获得邀请

(我是python新手,所以请不要苛刻地评判)

def updateInvite(pEmail,pSubj,iY, iM, iD, iHH, iMM):
    pytz_tz = pytz.timezone('America/New_York')
    tz = EWSTimeZone.localzone()    

    items = account.calendar.view(    
        start=tz.localize(EWSDateTime(iY, iM, iD, iHH, iMM)),        
        end=tz.localize(EWSDateTime(iY, iM, iD, iHH + 2, iMM)),        
        )`   
    for item in items:    
        sEventSubj = item.subject        
        item.save(update_fields=['required_attendees'])     

通过调用

pEmail = 'name.last@company.com'
sSubj  = 'Invite Test Meeting with Teams link'
iY = 2020
iD = 29
iM = 4
iHH = 16
iMM = 30
updateInvite(pEmail, sSubj, iY, iM, iD, iHH, iMM)

Tags: id电子邮件事件itemsitemtzimpytz
1条回答
网友
1楼 · 发布于 2024-10-02 04:34:04

为此,请使用项目附件。找到要附加到日历项目的邮件,并为其创建项目附件:

from exchangelib import ItemAttachment

# Create some filter to get the emails you want to attach
messages = account.inbox.all()[:5]
# Create a filter go get your calendar item
item = account.calendar.get(subject='Hello Python')
for message in messages:
    # Create the attachment and give it a name
    attachment = ItemAttachment(name='msg %s' % msg.id[:8], item=message)
    item.attach(attachment)

相关问题 更多 >

    热门问题