码迷,mamicode.com
首页 > 编程语言 > 详细

python3+selenium3学习——发送邮件

时间:2020-10-18 17:09:53      阅读:39      评论:0      收藏:0      [点我收藏+]

标签:path   其他   随机   参考   服务   路径   cts   图片   login   

1、安装yagmail

直接 pip install yagmail 

2、发送邮件前配置

技术图片

 

 3、发送邮件

参考代码;

import unittest
import HTMLTestRunner
import yagmail
import os

username = ‘1234567@qq.com‘
passwd = ‘abcdfefgh‘
smtp = yagmail.SMTP(user=username,
                    password=passwd,
                    host=‘smtp.qq.com‘,    # 其他服务器就  smtp.126.com
                    smtp_ssl=True
                    )

case_path = os.path.join(os.getcwd(),"case")  # 用例路径
report_path = "D:\\test02\\report"            # 报告存放路径

def all_case():
    discover = unittest.defaultTestLoader.discover(case_path,
                                               pattern="test*.py",
                                               top_level_dir = None)
    print(discover)
    return discover
if __name__ =="__main__":
    # runner = unittest.TextTestRunner()
    # runner.run(all_case())
    # html报告文件路径
    report_abspath = os.path.join(report_path,"result.html")
    fp = open(report_abspath,"wb")
    runner = HTMLTestRunner.HTMLTestRunner(stream=fp,
                                           title = u"自动化测试报告,测试结果如下:",
                                           description = u"用例执行情况:")

    # run所有用例
    runner.run(all_case())
    smtp.send(
        to = ‘qpbj0we@dingtalk.com‘,
        subject =‘发送邮件的标题‘,
        contents = ‘测试用例报告‘,
        attachments=r‘D:\test02\report\result.html‘
    )
    print(‘发送成功‘)
    fp.close()

 

ps: 发送邮件时,也可不用关键字

参考代码:

import yagmail

# 连接邮箱服务器
yag = yagmail.SMTP(user=‘234534@qq.com‘,
                   password=‘随机码‘,
                   host=‘smtp.qq.com‘,
                   smtp_ssl=True
                   )

# 发送邮件
yag.send([‘43353534@163.com‘,‘fdggdffdgd@dingtalk.com‘],
      ‘我的第一个电子邮件‘, [‘哈哈哈哈哈哈‘], [‘/Users/xuer/PycharmProjects/test01/32453563/fdgdf/20201016.09.33.16.jpg‘, ‘/Users/xuer/PycharmProjects/test01/xyuer/github/git_login.py‘] ) yag.close()

 

python3+selenium3学习——发送邮件

标签:path   其他   随机   参考   服务   路径   cts   图片   login   

原文地址:https://www.cnblogs.com/yuer02/p/12673222.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!