How can I send attachments in an email reply?

只愿长相守 提交于 2019-12-11 07:05:07

问题


I'm using the exchangelib package to connect to Exchange. I need to send attachments in a reply. When I send a normal message I add the attachment to the Message object like this:

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)

and to send a reply:

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

This works, but I don't now how to add attachments to the reply. I tried to set the attributes "attachments" and "attach" but the object doesn't have them.


回答1:


The Message.reply() method creates and sends a ReplyToItem item which doesn't support attachments. See https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/replytoitem

So if you want to send a reply that has attachments, just create a normal Message item that has a 'Re: some subject' title, contains the attachment, and quotes the original message, if that's needed.



来源:https://stackoverflow.com/questions/52628766/how-can-i-send-attachments-in-an-email-reply

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!