首页 > 解决方案 > 从 python 向特定的 Outlook 电子邮件发送电子邮件回复

问题描述

我在我的项目中添加了 Outlook 邮件解析功能。现在我想使用 python 代码回复特定的电子邮件。

这个怎么做?

标签: python-3.xemailsmtplib

解决方案


这是我的看法。我认为应该明确设置“回复”标题。可能的原因是它不如“主题”、“收件人”和“发件人”等标题使用得少。

python
Python 2.6.6 (r266:84292, May 10 2011, 11:07:28) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> MAIL_SERVER = 'smtp.domain.com'
>>> TO_ADDRESS = 'you@gmail.com'
>>> FROM_ADDRESS = 'email@domain.com'
>>> REPLY_TO_ADDRESS = 'email2@domain2.com'
>>> import smtplib
>>> import email.mime.multipart
>>> msg = email.mime.multipart.MIMEMultipart()
>>> msg['to'] = TO_ADDRESS
>>> msg['from'] = FROM_ADDRESS
>>> msg['subject'] = 'testing reply-to header'
>>> msg.add_header('reply-to', REPLY_TO_ADDRESS)
>>> server = smtplib.SMTP(MAIL_SERVER)
>>> server.sendmail(msg['from'], [msg['to']], msg.as_string())
{}

推荐阅读