五十六、企業(yè)qq發(fā)郵件腳本

心路歷程:本來想著按照時間創(chuàng)建文件夾,進入文件夾后進行執(zhí)行自動化腳本,結(jié)果手動執(zhí)行一掉毛病沒有,但是上了定時任務涼涼了。折騰了好久,想到了最佳方案。為什么要分別創(chuàng)建文件夾,因為執(zhí)行腳本會覆蓋

最佳方案就是:創(chuàng)建周一到周五,五個文件夾,每天執(zhí)行一遍,只保留5次歷史記錄,完美,判定周幾,既執(zhí)行周幾,完美、

下邊是發(fā)報告的腳本【周一到周五每天7點發(fā)送,要注意的是第一個一定要寫0,不然分分鐘沾滿你的郵箱,沒分發(fā)一個,發(fā)到你崩潰】

0 7 * * 1-5 ./etc/profile;/home/anaconda3/bin/python /usr/local/apache-tomcat-8.5.59/webapps/test/ti.py

import smtplib

from email.header import Header

from email.mime.text import MIMEText

import time

from datetime import datetime

receiver = ['li@shxseer.com', '155@qq.com','co@shxseer.com']? # 設置郵件接收人,這里是我的公司郵箱

host = 'smtp.exmail.qq.com'? # 設置發(fā)件服務器地址

port = 25? # 設置發(fā)件服務器端口號。注意,這里有SSL和非SSL兩種形式

sender = 'lii@shxseer.com'? # 設置發(fā)件郵箱

pwd = 'Se56'? # 設置發(fā)件郵箱的密碼

body = 'hello'? # 設置郵件正文,這里是支持HTML的

msg = MIMEText(body, 'html')? # 設置正文為符合郵件格式的HTML內(nèi)容

subject = '測試自動化報告'

dayOfWeek = datetime.now().isoweekday() ###返回數(shù)字1-7代表周一到周日

# print(dayOfWeek )

if dayOfWeek == 1:

? ? api ='http://1980/test/mon/log.html'

elif? dayOfWeek == 2:

? ? api ='http://1980/test/tue/log.html'

elif? dayOfWeek == 3:

? ? api ='http://1920/test/wed/log.html'

elif? dayOfWeek == 4:

? ? api ='http://19080/test/thu/log.html'

elif? dayOfWeek == 5:

? ? api ='http://1980/test/fri/log.html'

# print(api)

msg = MIMEText('<html><h2></h2><html><form action=“”method=“”><fieldset><legend>自動化測試報告</legend><div style="line-height:30px"align=“Center”>'

? ? ? ? ? ? ? '接口端</div>&nbsp;&nbsp;'+api+'<div style="line-height:40px"align=“Center”>'

? ? ? ? ? ? ? 'UI端</div>&nbsp;&nbsp;http://19080/svn_sale/UI/ui/run.log/log.html</fieldset></form>', 'html', 'utf-8')

msg['Subject'] = Header(subject, 'utf-8')

msg['from'] = sender? # 設置發(fā)送人

msg['to'] = ';'.join(receiver)? # 設置接收人

s = smtplib.SMTP(host, port)? # 注意!如果是使用SSL端口,這里就要改為SMTP_SSL

s.login(sender, pwd)? # 登陸郵箱

time.sleep(5)

s.sendmail(sender, receiver, msg.as_string())? # 發(fā)送郵件!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容