您已声明消息正文具有HTML内容(
"Content-Type:text/html")。换行符的HTML代码是
<br>。您应该将内容类型更改为,
text/plain或者将HTML标记用于换行符,而不要使用纯
n文本,因为纯文本在呈现HTML文档时会被忽略。
作为附带说明,也请查看电子邮件包。有一些类可以为您简化电子邮件的定义(带有示例)。
例如,您可以尝试(未试用):
import smtplibfrom email.mime.text import MIMEText# define contentrecipients = ["recipient_id@yahoo.com"]sender = "sender_id@gmail.com"subject = "report reminder"body = """Dear Student,Please send your reportThank you for your attention"""# make up messagemsg = MIMEText(body)msg['Subject'] = subjectmsg['From'] = sendermsg['To'] = ", ".join(recipients)# sendingsession = smtplib.SMTP('smtp.gmail.com', 587)session.starttls()session.login(sender, 'my password')send_it = session.sendmail(sender, recipients, msg.as_string())session.quit()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)