def _create_email_message(subject, body, recipient, sender, attachment=None):
msg = MIMEMultipart()
msg['Subject'] = subject
msg['To'] = ', '.join(recipient)
msg['From'] = sender
if "</html>" in body.lower():
content = MIMEText(body, 'html')
else:
content = MIMEText(body, 'plain')
msg.attach(content)
if attachment is not None:
fp = open(attachment, "rb") # Read as a binary file, even if it's text
att = MIMEApplication(fp.read())
att.add_header('Content-Disposition', 'attachment',
filename=os.path.basename(attachment))
fp.close()
msg.attach(att)
return msg
评论列表
文章目录