可以试试,以后用在报错发邮件

#!/usr/bin/env python3

# -*- coding: utf-8 -*-

from email.header import Header

from email.mime.text import MIMETextimport smtplib

#username="xxxxx@qq.com"

password = "授权码"

#授权码在QQ邮箱设置-账户下开通

from_addr = "xxxxxxx@qq.com"

to_addr = "xxxxx@qq.com"

smtp_server = "smtp.qq.com"

msg = MIMEText('hello, send by Python...', 'plain', 'utf-8')

msg['From'] = Header("ppyy", 'utf-8')

msg['To'] = Header("you", 'utf-8')

msg['Subject'] = Header('来自SMTP的问候……', 'utf-8')

try:

server = smtplib.SMTP_SSL(smtp_server,465)    

#如果不是Qq smtp.qq.com改为localhost

server.login(from_addr, password)   

server.sendmail(from_addr, to_addr, msg.as_string())   

server.quit()   

print("success")

except smtplib.SMTPException:

print("unsuccess")