如何在电子邮件回复中发送附件? [英] How can I send attachments in an email reply?

查看:377
本文介绍了如何在电子邮件回复中发送附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

并发送回复:

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.

推荐答案

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

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

因此,如果您要发送包含附件的回复,只需创建一个普通邮件,其标题为'Re: some subject',包含附件,并在需要时引用原始邮件即可.

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.

这篇关于如何在电子邮件回复中发送附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆