# coding:utf-8
import requests, json, yagmail, os, time
from config.config import *
def Send_Email(content):
day = time.strftime("%Y-%m-%d %H:%M*", time.localtime(time.time()))
basdir = os.path.abspath(os.path.dirname(__file__))
report_path = os.path.join(basdir + '\\report\\%s.html' % day)
log_path = os.path.join(basdir + '\\log\\%s.log' % day)
# 链接邮箱服务器
yag = yagmail.SMTP(user=SEND_USER, password=SEND_PW, host=EMAIL_HOST)
# 发送邮件
yag.send(RECEIVE_USER, '主题xx', content)
yag.send(RECEIVE_USER, '主题xx', content) # 多个邮箱
yag.send(RECEIVE_USER, '主题xx', content, [report_path, log_path]) # 带附件
return
def send_ding(content):
url = Ding_token
pagrem = {
"msgtype": "text",
"text": {
"content": content
},
"isAtAll": True
}
headers = {
'Content-Type': 'application/json'
}
f = requests.post(url, data=json.dumps(pagrem), headers=headers)
if f.status_code == 200:
return True
else:
return False