# 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. PHP0003:PHP基础2

    die表示结束,程序到此运行不过来了. 字符串比较是挨个比较

  2. Uva10791 唯一分解定理模板

    唯一分解定理: Uva10791 题意: 输入整数n,要求至少两个正整数,使得他们的最小公倍数为n,且这些整数的和最小 解法: 首先假设我们知道了一系列数字a1,a2,a3……an,他们的LCM是n, ...

  3. grid 布局(2)

    目录 grid 布局(2) grid区域属性 网格线名称 grid-template-areas 属性 grid-auto-flow 容器内子元素的属性 grid 布局(2) grid区域属性 网格线 ...

  4. 聊聊智能指针 auto_ptr、shared_ptr、weak_ptr和unique_ptr

    本文为转载:https://www.cnblogs.com/zeppelin5/p/10083597.html,对作者有些地方做了修正. 手写代码是理解C++的最好办法,以几个例子说明C++四个智能指 ...

  5. centos6/7 下升级openssl并安装python3

    今天是2019年的最后一天了,看了看自己今年写的随笔就一篇,实在有点少得可怜,就想着趁现在有点时间就再写一篇,^_^ centos6 或者centos 7 python 默认都是安装python 2 ...

  6. c#判断字符串是否可以转日期格式

    在C#中,对格式的判断有一类专门函数,那就是TryParse.TryParse在各个不同的类型类(如int,string,DateTime)中,都是存在的.在TryParse中一般有两个参数,一个是待 ...

  7. Django models 关联(一对多,多对多,一对一)

    参考:https://blog.csdn.net/houyanhua1/article/details/84953388

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

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

  9. Invalid Native Object

    发现是因为没有addChild到父节点上引起的

  10. 反射_python

    一.反射(通过字符串的形式去操作对象中的成员) 1.getattr:获取对象中的字段和方法 2.hasattr:判断对象里面是否有字段或方法 3.setattr:设置对象里面的字段或方法 4.dela ...