# coding =utf-8
import os
import unittest
import time
import datetime
import smtplib
from email.mime.text import MIMEText
from HTMLTestRunner import HTMLTestRunner def all_cases():
case_path = os.getcwd() discover = unittest.defaultTestLoader.discover(case_path, pattern='test*.py', top_level_dir=None)
return discover def run(report_path):
with open(report_path, 'wb') as f:
runner = HTMLTestRunner(stream=f, title="interface report", description="results like following:", verbosity=2)
runner.run(all_cases())
f.close() def timer(report_path, hour, minute):
flag = 1
while flag:
while flag:
now = datetime.datetime.now()
if now.hour == hour and now.minute == minute:
break
time.sleep(10)
# run(report_path)
email_send(report_path)
flag = 0 def email_send(report_path,str_sender,receiver,author_code,smtp_server="smtp.qq.com",smtp_int_port=465):
run(report_path)
msg_from = str_sender # sender
passwd = author_code # authentication code
msg_to = receiver # receiver
#如果多个接受者用列表 ['1932390299@qq.com','1393232463@qq.com']
subject = "python_email_test"
f = open(report_path, 'rb')
mail_body = f.read()
f.close()
msg=MIMEText(mail_body, _subtype='html', _charset='utf-8') msg['Subject'] = subject
msg['From'] = msg_from
msg['To'] = msg_to
try:
s = smtplib.SMTP_SSL(smtp_server, smtp_int_port)
s.login(msg_from, passwd)
s.sendmail(msg_from, msg_to, msg.as_string())
print("send success")
except smtplib.SMTPException as e:
print("send fail")
finally:
s.quit() def get_report_path():
job_name = time.strftime('job_%Y%m%d%H%M%S', time.localtime()) + '.html'
path = os.path.join(os.path.dirname(__file__), 'report')
report_path = os.path.join(path, job_name)
return report_path

上面是很久以前的没更新:邮件发送见最新的文章封装很全面写了一次https://www.cnblogs.com/SunshineKimi/p/10629267.html

定时计划参考最新的机制schedule文章  :https://www.cnblogs.com/SunshineKimi/p/10630784.html

报告选型见我的报告模块:https://www.cnblogs.com/SunshineKimi/category/1426942.html

python 自动化实现定时发送html报告到邮箱的更多相关文章

  1. 全网最全的Windows下Anaconda2 / Anaconda3里Python语言实现定时发送微信消息给好友或群里(图文详解)

    不多说,直接上干货! 缘由: (1)最近看到情侣零点送祝福,感觉还是很浪漫的事情,相信有很多人熬夜为了给爱的人送上零点祝福,但是有时等着等着就睡着了或者时间并不是卡的那么准就有点强迫症了,这是也许程序 ...

  2. python自动化之邮件发送

    #!/usr/bin/env python # -*- coding:utf-8 -*- import smtplib from email.mime.multipart import MIMEMul ...

  3. python自动化--批量执行测试之生成报告

    一.生成报告 1.先执行一个用例,并生成该用例的报告 # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webd ...

  4. python学习===实现定时发送,方法一

    #比如每3秒打印一次helloworld:from threading import Timer def printHello(): print "Hello World" t = ...

  5. 用python自制微信机器人,定时发送天气预报

    0 引言 前段时间找到了一个免费的天气预报API,费了好段时间把这个API解析并组装成自己想用的格式了,就想着如何实现每天发送天气信息给自己.最近无意中发现了wxpy库,用它来做再合适不过了.以下是w ...

  6. Python+request+ smtplib 测试结果html报告邮件发送(上)《五》

    此方法通用适合所有邮箱的使用,只需注意几个点,如下: QQ邮箱.其他非QQ邮箱的写法,区别点如下: #--------------------------使用腾讯企业邮箱作为发件人的操作如下----- ...

  7. 10分钟教你用Python打造天气机器人+关键字自动回复+定时发送

    01 前言 Hello,各位小伙伴.自上次我们介绍了Python实现天气预报的功能以后,那个小程序还有诸多不完善的地方,今天,我们再次来完善一下我们的小程序.比如我们想给机器人发“天气”等关键字,它就 ...

  8. python实现定时发送系列

    1.发送邮件实现 2.定时任务实现 3.定时发送邮件实现 4.微信定时发送信息 详细源代码见:https://github.com/15387062910/timing_send 参考: 廖雪峰博客 ...

  9. Selenium2+python自动化39-关于面试的题

    前言 最近看到群里有小伙伴贴出一组面试题,最近又是跳槽黄金季节,小编忍不住抽出一点时间总结了下, 回答不妥的地方欢迎各位高手拍砖指点.   一.selenium中如何判断元素是否存在? 首先selen ...

随机推荐

  1. Codeforces Round #622(Div 2) C1. Skyscrapers (easy version)

    题目链接: C1. Skyscrapers (easy version) 题目描述: 有一行数,使得整个序列满足 先递增在递减(或者只递增,或者只递减) ,每个位置上的数可以改变,但是最大不能超过原来 ...

  2. vue自定义插件

    1.新建js文件 utils.js,自定义方法 let local = { say() { console.log('我是插件里面自定义的方法') } } export default { insta ...

  3. tsocks代理git wget

    使用clash时, 命令行的wget和git操作可能没有被代理 安装tsocks: apt-get install tsocks 修改配置文件: vi /etc/tsocks.conf 找到: ser ...

  4. JN_0009:win下快捷键注销,关机,重启

    注销:  wn + x  + U  再按 I 键 关机: win + x  + U  再按 U 键 重启: win + x  + U  再按 R 键

  5. 深入浅出Mybatis系列二-配置简介(mybatis源码篇)

    注:本文转载自南轲梦 注:博主 Chloneda:个人博客 | 博客园 | Github | Gitee | 知乎 上篇文章<深入浅出Mybatis系列(一)---Mybatis入门>, ...

  6. cli4适配移动端

    1.首先在项目中安装以下依赖 npm install px2rem-loader --savenpm install amfe-flexible --savenpm install postcss-p ...

  7. Linux虚拟化 xen的工具栈介绍

    试验环境centos6.10 xen的工具栈介绍: 查看xl目录的帮助:xl help 查看xen下安装了哪些虚拟机:xl list # xl list Domain-0 Name ID Mem VC ...

  8. [Python]jieba切词 添加字典 去除停用词、单字 python 2020.2.10

    源码如下: import jieba import io import re #jieba.load_userdict("E:/xinxi2.txt") patton=re.com ...

  9. mysql 基础sql语法总结 (二)DML

    二.DML(增.删.改) 1)插入数据 第一种写法:INSERT INTO 表名 (列名1,列名2,,......)VALUES(列值1,列值2,......) 第二种写法:INSERT INTO 表 ...

  10. ASP.NET MVC 给Action的参数赋值的方式

    Action指的是Controller类中的方法,如上文中的Index. Action参数的三种常见类型:Model类型.普通参数.FormCollection Model类型 我们可以直接在地址栏后 ...