def build_mime_text(recipients, subject, message):
"""
Puts message data into MIME format
:param recipients: array of email addresses to send email to
:param subject: subject of email
:param message: body of email
:return MIMEMultipart object
"""
# Record the MIME types of text/plain and text/html.
part1 = MIMEText(html2text.html2text(message), 'plain')
part2 = MIMEText(message, 'html')
# Attach parts into mime message container.
body = MIMEMultipart('alternative')
body['Subject'] = subject
body['From'] = options.smtp_from
body['To'] = ",".join(recipients)
body.attach(part1)
body.attach(part2)
raise Return(body)
评论列表
文章目录