# vi sendmail.py
# python sendmail.py 运行即可
import smtplib #smtp服务器用的包
from email.mime.text import MIMEText #邮件用得包
authEmail = "xxx@qq.com" #开启smtp服务的邮箱
authCode = "xxx" #获取到的授权码 http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256
toEmail = "xxx@163.com"
message = MIMEText("大家好,我们吃鸡","plain","utf-8")
message["Subject"] = "标题名"
message["To"] = toEmail
message["From"] = authEmail
smtp = smtplib.SMTP_SSL("smtp.qq.com",465) #465或587是一个固定值,smtp服务器端口号
smtp.login(authEmail,authCode)
smtp.sendmail(authEmail, [toEmail],message.as_string())
smtp.quit()