Commit c9adf357 by zhangchunyao

code commit

parent 2834ac3c
#coding=utf-8
import smtplib
from email.mime.text import MIMEText #MIMRText()定义邮件正文
from email.mime.multipart import MIMEMultipart #MIMEMulipart模块构造带附
def sendResultMail(smtpSever,sendUser,sendPwd,recvUser):
#发送邮件的服务器
#smtpserver = 'smtp.sina.com'
smtpserver =smtpSever
#发送邮件用户和密码
#user ="xxx@sina.com"
#password = "xxx"
user = sendUser
password = sendPwd
#发送者
#sender = "xxx@sina.com"
sender = sendUser
#接收者
#receiver = "1xxx@qq.com"
receiver = recvUser
#邮件主题
subject = "接口自动化执行结果"
#发送附件
sendfile = open("/opt/apitest/interfacedata/apitest.xls","rb").read()
att = MIMEText(sendfile,"base64","utf-8")
att["Content-Type"] = "application/octet-stream"
att["Content-Disposition"] = "attachment;filename = 'autoInterfaceResult.xls'"
#msghtml = MIMEText('<h1 style="color:red;font-size:100px">各位好,附件为接口自动化测试详细结果,请查阅</h1><img src="cid:small">', 'html', 'utf-8')
msghtml = MIMEText('<h2 style="color:red;font-size:50px">各位好,附件为接口自动化测试详细结果,请查阅</h2>', 'html', 'utf-8')
#msg = MIMEText('接口自动化测试结果', 'plain', 'utf-8')
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = subject
msgRoot['from'] = "测试服务器"
msgRoot['To'] = receiver
msgRoot.attach(att)
msgRoot.attach(msghtml)
#msgRoot.attach(msg)
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(user,password)
smtp.sendmail(sender,receiver,msgRoot.as_string())
smtp.quit()
#coding:utf-8
from interfacetest import xlsx_open
from interfacetest import xlsx_save
from interfacetest import dosheet
from xlutils.copy import copy
from resultMail import sendResultMail
APIPATH='/opt/apitest/interfacedata/apitest.xls'
# 打开文件
brd = xlsx_open(APIPATH)
# copy文件用于写入结果a
bwt = copy(brd)
# 获取cookie
# url = "http://xxx"
# data = {
# "name":"xxx",
# "password":"xxx"
# }
# response = requests.post(url,data)
# c = response.cookies
# cookies = dict(c)
# 执行文件
dosheet(brd,bwt,0)
# dosheet(brd, bwt, 1, cookies)
# 保存
xlsx_save(bwt,APIPATH)
smtpSer ="smtp.exmail.qq.com"
# 测试服务器群发测试组成员
sendUser ="apitest@demogic.com"
sendPwd ="Api@201906"
recvUser ="test@demogic.com"
#recvUser = "lienlin@demogic.com"
#recvUser = "zhangchunyao@demogic.com"
sendResultMail(smtpSer,sendUser,sendPwd,recvUser)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment