我正在使用smtplib创建MIMEMultipart电子邮件,结果是一个标题,如下所示。
MIME-Version: 1.0
Content-Type: multipart/alternative; charset="utf-8"; boundary="===============2613033831060434871=="
Content-Transfer-Encoding: base64
Subject: Your report is ready
From: no-reply@example.com
To: someone@example.com
这是有效的电子邮件标题吗?除了一位在显示电子邮件正文之前遇到其电子邮件被截断的人以外,没有任何投诉。他们声称这是因为Content-Type出现在错误的位置。
这是创建消息的方式
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from cl.library.htmlutils import html_to_text
def make_multipart_email(from_addr, to_addr, html, subject=None, text=None):
text = text or html_to_text(html)
msg = MIMEMultipart('alternative')
msg.set_charset('utf8')
msg['Subject'] = subject
msg['From'] = from_addr
msg['To'] = to_addr
msg.attach(MIMEText(text, 'plain', 'UTF-8'))
msg.attach(MIMEText(html, 'html', 'UTF-8'))
return msg