You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

emmail.py 1.3 KiB

2 years ago
1234567891011121314151617181920212223242526272829303132333435
  1. # -*- coding: utf-8 -*-
  2. # @Author : leizi
  3. import smtplib, time, os
  4. from email.mime.text import MIMEText
  5. from email.mime.multipart import MIMEMultipart
  6. import yaml
  7. def load_emil_setting(): # 从配置文件中加载获取email的相关信息
  8. filepath = os.path.join(os.path.join(os.getcwd(), 'config'), 'email.yaml')
  9. data_file = open(filepath, "r")
  10. datas = yaml.load(data_file, Loader=yaml.FullLoader)
  11. data_file.close()
  12. return (datas['foremail'], datas['password'], datas['toeamil'], datas['title'])
  13. def sendemali(filepath): # 发送email
  14. from_addr, password, mail_to, mail_body = load_emil_setting()
  15. msg = MIMEMultipart()
  16. msg['Subject'] = '接口自动化测试报告'
  17. msg['From'] = '自动化测试平台'
  18. msg['To'] = mail_to
  19. msg['Date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z')
  20. att = MIMEText(open(r'%s' % filepath, 'rb').read(), 'base64', 'utf-8')
  21. att["Content-Type"] = 'application/octet-stream'
  22. att["Content-Disposition"] = 'attachment; filename="pyresult.html"'
  23. txt = MIMEText("这是测试报告的邮件,详情见附件", 'plain', 'gb2312')
  24. msg.attach(txt)
  25. msg.attach(att)
  26. smtp = smtplib.SMTP()
  27. server = smtplib.SMTP_SSL("smtp.qq.com", 465)
  28. server.login(from_addr, password)
  29. server.sendmail(from_addr, mail_to, msg.as_string())
  30. server.quit()

Introduction

生成接口测试报告

No topics

Contributors (2)