导包
import smtplib
from email.mime.text import MIMEText
from email.header import Header
发送邮件服务器
smtpserver = ‘smtp.qq.com’
发送邮箱
sender = ‘guaishounan@qq.com’
发送邮箱用户名/授权码(授权码获取方式:https://service.mail.qq.com/cgi-bin/help?id=28&no=1001256&subtype=1)
username = ‘guaishounan@qq.com’
password = ‘oifuds9vuie09vv’
接收邮箱
receiver = ‘guaishounan@qq.com’
邮件主题
subject = ‘python email test’
邮件正文
msg = MIMEText(‘guaishounan’,‘text’,‘utf-8’)
msg[‘Subject’] = Header(subject, ‘utf-8’)
连接发送邮件
smtp = smtplib.SMTP()
smtp.connect(‘smtp.qq.com’)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()