在Python email/smtplib中设置不同的回复消息
我正在使用 Python email 和 smtplib 从 Python 发送电子邮件。我正在使用我的 Gmail 凭据通过 Gmail SMTP 服务器执行此操作。这工作正常,但我想指定一个与 from
地址不同的 Reply-to
电子邮件地址,以便回复发送到单独的地址(非 Gmail)。
我尝试创建一个 reply to
参数,如下所示:
msg = MIMEMultipart()
msg['From'] = "[email protected]"
msg['To'] = to
msg['Subject'] = subject
msg['Reply-to'] = "[email protected]"
但这不起作用。在 Python 文档中找不到任何相关信息。
I am using Python email and smtplib to send an email from Python. I am doing this via the Gmail SMTP server using my Gmail credentials. This works fine, however I would like to specify a Reply-to
email address different from the from
address, so that replies go to a separate address (non-Gmail.)
I have tried creating a reply to
parameter like this:
msg = MIMEMultipart()
msg['From'] = "[email protected]"
msg['To'] = to
msg['Subject'] = subject
msg['Reply-to'] = "[email protected]"
But this doesn't work. Can't find any info on this in the Python docs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是我的看法。我认为应该明确设置“Reply-To”标头。可能的原因是它不如“主题”、“收件人”和“发件人”等标头常用。
Here's my take on it. I believe that the "Reply-To" header should be set explicitly. The likely reason is that it's less commonly used than headers such as "Subject", "To", and "From".
我有同样的问题,我所要做的就是将标题设置为小写,如下所示:
I had the same question and all I had to do to make it work was to set the header in lowercase like so:
对于 2021 年的 Python3,我建议使用以下内容来构造消息:
然后,为了发送消息,我在邮件服务器上使用以下内容,该邮件服务器在端口 587 上使用 StartTLS:
For Python3 in 2021 I would recommend the following to construct the message:
Then to send the message I use the following for my mail server which uses StartTLS on port 587:
正如 Jonathon Reinhart 指出的那样,“To”需要大写:
As Jonathon Reinhart pointed out, the "To" needs to be upper case:
只有这个对我有用:
看这里:使用 python 3.4 回复电子邮件 按城市
Only this worked for me:
Look here: Reply to email using python 3.4 by urban