selenium自动化测试笔记3-高级应用邮件发送

附上自己写的代码参考:

import os,time,smtplib
from email.header import Header
from email.mime.text import MIMEText
#定义发送邮件的设置
def sentemail(file_new):
    #发送方
    mail_from = 'xxxxxxx@163.com'
    #接收方
    mail_to = 'xxxxxx@qq.com'
    #发送方用户名和密码
    username = 'xxxxxxx@163.com'
    password = '***********'
    #发送文件标题
    subject = '测试报告'
    #打开文件
    f= open(file_new,'rb')
    #读取文件里面的内容
    mail_body = f.read()
    f.close()
    #发送文件的格式
    msg = MIMEText(mail_body,'html','utf-8')
    #标题格式
    msg['Subject'] = Header(subject, 'utf-8')
    #来自于谁
    msg['From'] = '谢'
    #发送给谁
    msg['To'] = 'XXXXXXX@qq.com'
    #发送时间
    msg['date'] = time.strftime('%a,%d %b %Y %H:%M:%S ,%z')
    #发送邮箱的服务器
    smtp = smtplib.SMTP()
    #服务器的类型
    smtp.connect('smtp.163.com')
    #登录,要设置授权才可以
    smtp.login(username, password)
    smtp.sendmail(mail_from, mail_to, msg.as_string())
    smtp.quit()
    print("'email has send out")
#获取最新的报告
def sendrepost(result_dir):
    #判断文件路径
    lists = os.listdir(result_dir)
    #根据系统时间获取最新的文件
    lists.sort( key=lambda fn: os.path.getmtime(result_dir + '\\' + fn) if not os.path.isdir(result_dir + "\\" + fn) else 0)
    print(u"最新文件为:" + lists[-1])
    #最新文件的路径
    file_new = os.path.join(result_dir, lists[-1])
    print(file_new)
    #调用发送最新邮件
    sentemail(file_new)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值