1

我正在使用 exchangelib 包连接到 Exchange。我需要在回复中发送附件。当我发送普通消息时,我将附件添加到 Message 对象,如下所示:

message = Message()
message.account = account
message.subject = 'subject'
message.body = 'text'
message.to_recipients = [Mailbox(email_address='example@gmail.com')]
message.cc_recipients = ['example2@gmail.com']

for attachment in attachments or []:
    with open(attachment['path'], 'rb') as f:
        file = FileAttachment(name=attachment['file_name'], content=f.read())
        message.attach(file)

并发送回复:

reply = message.reply(
    subject='Re: subject',
    body='texto',
    to_recipients=['example@gmail.com']
)

这可行,但我现在不知道如何在回复中添加附件。我试图设置属性“附件”和“附件”,但对象没有它们。

4

1 回答 1

1

Message.reply()方法创建并发送ReplyToItem不支持附件的项目。请参阅https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/replytoitem

因此,如果您想发送带有附件的回复,只需创建一个普通的消息项目,该项目具有'Re: some subject'标题、包含附件并在需要时引用原始消息。

于 2018-10-05T11:56:08.910 回答