【发布时间】:2015-10-04 16:25:36
【问题描述】:
我正在尝试使用 Python 3.4 回复电子邮件。电子邮件的收件人将使用 Outlook(很遗憾),Outlook 能够识别回复并正确显示线程非常重要。
我目前拥有的代码是:
def send_mail_multi(headers, text, msgHtml="", orig=None):
"""
"""
msg = MIMEMultipart('mixed')
# Create message container - the correct MIME type is multipart/alternative.
body = MIMEMultipart('alternative')
for k,v in headers.items():
if isinstance(v, list):
v = ', '.join(v)
msg.add_header(k, v)
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
body.attach(MIMEText(text, 'plain'))
if msgHtml != "": body.attach(MIMEText(msgHtml, 'html'))
msg.attach(body)
if orig is not None:
msg.attach(MIMEMessage(get_reply_message(orig)))
# Fix subject
msg["Subject"] = "RE: "+orig["Subject"].replace("Re: ", "").replace("RE: ", "")
msg['In-Reply-To'] = orig["Message-ID"]
msg['References'] = orig["Message-ID"]+orig["References"].strip()
msg['Thread-Topic'] = orig["Thread-Topic"]
msg['Thread-Index'] = orig["Thread-Index"]
send_it(msg['From'], msg['To'], msg)
- 函数
get_reply_message正在删除所有附件,如this answer。 -
send_it函数设置 Message-ID 标头并使用正确的 SMTP 配置。然后它调用smtplib.sendmail(fr, to, msg.as_string()) - Outlook 收到电子邮件但无法识别/显示线程。但是,该线程似乎是消息的附件(可能由
msg.attach(MIMEMessage(...))
关于如何做到这一点的任何想法?我错过了任何标题吗?
干杯,
安德烈亚斯
【问题讨论】:
标签: python email outlook smtp reply