python发送邮件,,# 使用163邮箱发
python发送邮件,,# 使用163邮箱发
# 使用163邮箱发送邮件# 1.先导入smtplib库用来发送邮件,导入MIMEText库用来做纯文本的邮件模板import smtplibfrom email.mime.text import MIMEText# 发送带附件的需要导入另外一个模块MIMEMultipartfrom email.mime.multipart import MIMEMultipart
------------------------------------------------------------------------------------------# 2.定义附件路径file_path = r‘D:\Python_Script\TetsInterface\reports\1576631030.html‘# 打开文件with open(file_path,‘rb‘)as fp: file_data = fp.read()# ----------------------------------准备跟发件相关参数---------------------------------------smtp_server = ‘smtp.163.com‘ # 发件服务器prot = 0 # 端口sender_user = ‘[email protected]‘ # 发件人账号pwd = ‘*******‘ # 发件人密码receivers = [‘[email protected]‘,‘[email protected]‘] # 需要多个收件人# 4. --------------------------------编辑邮件内容-------------------------------------------subject = ‘这是接口自动化测试报告‘ # 邮件主题msg = MIMEMultipart()msg[‘from‘] = sender_user # 定义发件人msg[‘to‘] = ‘;‘.join(receivers) # 定义收件人,多个收件人不可直接接收列表,需要通过分号隔开msg[‘subject‘] = subject # 邮件主题body = MIMEText(file_data,‘html‘,‘utf-8‘) # 邮件正文msg.attach(body)# ------------------------------------附件--------------------------------------------------accessory = MIMEText(file_data,‘base64‘,‘utf-8‘)accessory["Content-Type"] = "application/octet-stream"accessory["Content-Disposition"] = ‘attachment; filename="test_report.html"‘ #附件重命名msg.attach(accessory)# -----------------------------------准备发送------------------------------------------------smtp = smtplib.SMTP()smtp.connect(smtp_server)smtp.login(sender_user,pwd) #登录smtp.sendmail(sender_user,receivers,msg.as_string()) # 发送smtp.quit() # 退出
python发送邮件
相关内容
- Python可视化 | Seaborn包—kdeplot和distplot,,import pan
- Python基础系列讲解-自动控制windows桌面,,原链接:htt
- Python对MySQL进行增删查改,,python连接My
- python基础知识(字符串),python字符串比较,定义字符串
- Python 基础总结篇,机械基础总结,变量及数据类型Num
- Python入门学习(二)——函数篇,,1.函数要调用一个函
- Python进程、线程、协程详解,线程进程协程,进程与线程
- python 怎么发送邮件,python发送邮件,一、准备1、pop3
- 炫酷!一边玩游戏一边就能学好Python!,玩游戏,当前
- python 使用 requests 做 http 请求,python3requests,1. getimpo
评论关闭