1、确认发送邮箱的信息
确认smtp服务器
smtpserver='smtp.163.com'
邮箱账号和邮箱授权码
username='***@163.com'
password='发送邮箱开启smtp服务时的授权码'
2、确认接收邮箱的信息
receiver='***@qq.com'接收邮件的地址
3、确认邮件内容信息
message=MIMEMultipart('related')这个时固定的写法
subject='测试报告',邮件的主题
fujian=MIMEText(open("report.html",rb).read(),'html','utf-8')附件所在的路径,附件的格式,附件的编码
message['form']=username 邮件中的发件人信息
message['to']=receiver邮件中的收件人信息
message['subject']=subject 邮件中的标题
message.attach('fujian')邮件中上传附件
4、发送邮件
smtp=smtplib.SMTP()邮箱服务器实例化
smtp.connect(smtpserver)连接发送邮箱的服务器
smtp.login(username,password)登录发件箱
smtp.sendmail(username,receiver,message.as_string())发送邮件
stmp.quit()退出邮箱