如果消息头,有效负载包含非ASCII字符,则应对其进行编码:
#!/usr/bin/env python# -*- coding: utf-8 -*-from email.header import Headerfrom email.mime.text import MIMETextfrom getpass import getpassfrom smtplib import SMTP_SSLlogin, password = 'user@gmail.com', getpass('Gmail password:')recipients = [login]# create messagemsg = MIMEText('message body…', 'plain', 'utf-8')msg['Subject'] = Header('subject…', 'utf-8')msg['From'] = loginmsg['To'] = ", ".join(recipients)# send it via gmails = SMTP_SSL('smtp.gmail.com', 465, timeout=10)s.set_debuglevel(1)try: s.login(login, password) s.sendmail(msg['From'], recipients, msg.as_string())finally: s.quit()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)