python3 发送QQ邮件

from email.header import Header
from email.mime.text import MIMEText
from smtplib import SMTP_SSL

email_sevrer='smtp.qq.com'#qq邮箱的服务器
email_sender_qq='123456'#发送邮件人的qq号码
email_sender='123456@qq.com'#发送邮件人的QQ邮箱
email_pwd='123456'#授权码,不会获取授权的同学可以看这里:http://jingyan.baidu.com/article/b0b63dbf1b2ef54a49307054.html
email_receiver='3270740288@qq.com'#接收人的qq邮箱

sever=SMTP_SSL(email_sevrer)#连接qq邮箱服务器
sever.login(email_sender_qq,email_pwd)#登录的qq和授权码

email=MIMEText('haha','plain','utf-8')#三个参数:第一个为文本内容,第二个 plain 设置文本格式,第三个 utf-8 设置编码
email['Subject']=Header('**','utf-8')
email['From']=email_sender
email['To']=email_receiver
sever.sendmail(email_sender,email_receiver,email.as_string())#发送邮件
sever.quit()
posted @ 2017-09-18 14:28  糖宝虫  阅读(198)  评论(0编辑  收藏  举报