python 给多人发送邮件,且将结果添加为附件
import unittest,HTMLTestRunner
import os
def runa():
path=os.getcwd()
print(path)
a=unittest.defaultTestLoader.discover(path,
pattern='login*.py')
al=unittest.TestSuite()
al.addTest(a)
#print(al)
return al import os,time
from email.mime.text import MIMEText
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.utils import formataddr
import smtplib
def lu(path):
filesn=os.listdir(path)
filesn.sort(key=lambda x:os.path.getmtime(path+x))
#luf=path+filesn[-1]
luf=os.path.join(path+filesn[-1])
return luf
#print(lu("D:\\study\\python_api_test\\test1204\\"))
def send_out(luf):
x=open(luf,'rb')
email=x.read()
x.close()
usernames='371933505@qq.com'
passwd='kclpuvarbapocagj' #此处密码错误,运行时,修改为正确密码
sender='371933505@qq.com'
receiver=['371933505@qq.com','1059084854@qq.com']
info=MIMEMultipart()
info['From']=Header("测试人:慧慧<%s>"%sender,'utf-8')
info['To']=Header("请老板们查阅<%s>"%receiver,'utf-8')
info['Subject']=Header('这是python自动化测试报告...','utf-8')
info.attach(MIMEText(email,'html','utf-8'))
attach1=MIMEText(open(luf,'rb').read(),'base64','utf-8')
attach1['Content-Type']='application/octet-stream'
attach1["Content-Disposition"]='attachment;filename="result.html"'
info.attach(attach1)
smtp=smtplib.SMTP_SSL("smtp.qq.com",465)
smtp.login(usernames,passwd)
smtp.sendmail(sender,receiver,info.as_string())
smtp.quit()
print("邮件已发出!请注意查收!") if __name__=="__main__":
#unittest.TextTestRunner().run(runa())
htmlrun=unittest.TextTestRunner()
result=os.path.join(os.getcwd()+"\\result.html") #无result.html,则会自动创建
print(result)
a=open(result,'wb')
htmlrun=HTMLTestRunner.HTMLTestRunner(stream=a,
title='自动化测试结果',
description='具体结果如下:',
verbosity=2)
htmlrun.run(runa())
a.close()
path="D:\\study\\python_api_test\\test1204\\"
hehe=lu(path)
send_out(hehe)
======================================================================
小结:
1.python使用了
a=['ab','ee']
b=';'.join(a) #输出结果为ab;ee
2.使用了email中的MIMEMutipart()
附件att1
info=MIMEMutipart()
att1=MIMEText(open('**文件','rb').read(),'base64','utf-8')
att1=['Content-Type"]='application/octet-stream'
att1=['Content-Disposition']='attachment;filename="可随意命名"'
info.attach(att1)
Text1=MIMEText(open('**文件.html','rb').read())
info.attach(Text1,'html','utf-8')
python 给多人发送邮件,且将结果添加为附件的更多相关文章
- Python使用SMTP发送邮件[HTML格式、送带附件]
SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. python的smtplib提供了一 ...
- python使用qq服务器发送邮件
python使用qq服务器发送邮件 直接上代码: #!/usr/bin/python2.7 #-*- coding: UTF-8 -*- # sendmail.py # # init created: ...
- Python qq企业邮箱发送邮件
Python qq企业邮箱发送邮件 进入客户端设置: 下面是代码部分: from email.header import Header from email.mime.text import MIME ...
- Python IAQ中文版 - Python中少有人回答的问题
Python中少有人回答的问题 The Python IAQ: Infrequently Answered Questions 1 Q: 什么是"少有人回答的问题(Infrequently ...
- 批量群发,营销必备!Python代码实现自动发送邮件!
在运维开发中,使用 Python 发送邮件是一个非常常见的应用场景.今天一起来探讨一下,GitHub 的大牛门是如何使用 Python 封装发送邮件代码的. 一般发邮件方法 SMTP是发送邮件的协议, ...
- java 利用spring JavaMailSenderImpl发送邮件,支持普通文本、附件、html、velocity模板
java 利用spring JavaMailSenderImpl发送邮件,支持普通文本.附件.html.velocity模板 博客分类: Java Spring 本文主要介绍利用JavaMailS ...
- c#发送邮件,可发送多个附件
1:创建SendMail类 2:调用方法 SendMail send = new SendMail("123456@qq.com", "123456@163.com&qu ...
- Newtonsoft.Json C# Json序列化和反序列化工具的使用、类型方法大全 C# 算法题系列(二) 各位相加、整数反转、回文数、罗马数字转整数 C# 算法题系列(一) 两数之和、无重复字符的最长子串 DateTime Tips c#发送邮件,可发送多个附件 MVC图片上传详解
Newtonsoft.Json C# Json序列化和反序列化工具的使用.类型方法大全 Newtonsoft.Json Newtonsoft.Json 是.Net平台操作Json的工具,他的介绍就 ...
- Python中使用SMTP发送邮件以及POP收取邮件
假设我们自己的电子邮件地址是from@163.com,对方的电子邮件地址是to@sina.com(这里的地址虚拟的),现在我们用Outlook或者Foxmail之类的软件写好邮件,填上对方的Email ...
随机推荐
- 『003』Shell命令
『001』索引-Linux Shell Command shell命令 <01>[线上查询及帮助][001]-[001] [001]- 点我快速打开文章[man][help][已改版] & ...
- 断点调试debugger
断点调试有两种打点方式 (1)控制台手动打点 (2)代码中添加 debugger打点 .
- leetcode 1041. 困于环中的机器人
题目地址 : https://leetcode-cn.com/problems/robot-bounded-in-circle/ 在无限的平面上,机器人最初位于 (0, 0) 处,面朝北方.机器人可以 ...
- Spring Cloud 服务之间调用
微服务之多个服务间调用 现在又一个学生微服务 user 和 学校微服务 school,如果user需要访问school,我们应该怎么做? 1.使用RestTemplate方式 添加config imp ...
- WPF 精修篇 用户控件
原文:WPF 精修篇 用户控件 增加用户控件 数据绑定还是用依赖属性 使用的事件 就委托注册一下 public delegate void ButtonClick(object b,EventArgs ...
- Redis思维导图
Redis基本数据结构 1.String 1.1 数据结构 long len byte数组长度 long free 可用数组长度 char buff[] 数据内容 1.2 命令 键值:设置值通过字符串 ...
- Nginx与keepalived实现高可用
主keepalived设置 #安装keepalived [root@localhost ~]# yum -y install keepalived #安装nginx [root@localhost ~ ...
- [Pytorch Bug] "EOFError: Ran out of input" When using Dataloader with num_workers=x
在Windows上使用Dataloader并设置num_workers为一个非零数字,enumerate取数据时会引发"EOFError: Ran out of input"的报错 ...
- python request获取ip、获取登录设备
from flask import request 获取ip request.remote_addr 获取登录设备 request.user_agent.string
- Java生鲜电商平台-订单中心服务架构与异常订单逻辑
Java生鲜电商平台-订单中心服务架构与异常订单逻辑 订单架构实战中阐述了订单系统的重要性,并从订单系统的信息架构和流程上对订单系统有了总体认知,同时还穿插着一些常见的订单业务规则和逻辑.上文写到订单 ...