123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #导入smtplib和MIMEText
- import smtplib
- from email.mime.text import MIMEText
- import json;
- import requests;
- #要发给谁
- mail_to="xiepan1990929@126.com"
- class MailUtil(object):
- def __init__(self):
- i=0;
- def send(self,to_list,sub,content):
- #设置服务器,用户名、口令以及邮箱的后缀
- mail_host="smtp.163.com"
- mail_user="vankye"
- mail_pass="chy520"
- mail_postfix="163.com"
- me=mail_user+"<"+mail_user+"@"+mail_postfix+">"
- msg = MIMEText(content)
- msg['Subject'] = sub
- msg['From'] = me
- msg['To'] = to_list
- try:
- s = smtplib.SMTP()
- s.connect(mail_host)
- s.login(mail_user,mail_pass)
- s.sendmail(me, to_list, msg.as_string())
- s.close()
- #print '1'
- return True
- except Exception:
- #print '2'
- return False;
- def dingtalk(self,msg, webhook):
- headers = {'Content-Type': 'application/json; charset=utf-8'}
- data = {'msgtype': 'text', 'text': {'content': msg}, 'at': {'atMobiles': [], 'isAtAll': False}}
- post_data = json.dumps(data)
- # response = requests.post(webhook, headers=headers, data=post_data)
- # return response.text
- if __name__ == '__main__':
- # 輸出結果
- i=0;
- ms = MailUtil();
- # if ms.send("loemkie@163.com","17816189000","提交成功"):
- # print ("发送成功")
- # i=i+1;
- # if i>10:
- # exit
- # else:
- # print ("发送失败")
- # if ms.send("18868188188@163.com","17816189000","提交成功"):
- # print ("发送成功")
- # i=i+1;
- # if i>10:
- # exit
- # else:
- # print ("发送失败")
- webhook = 'https://oapi.dingtalk.com/robot/send?access_token=64d8b2c7fed4949e9433b807c7c5559939f1517af8f77c1dacb4de19c6910b56'
- ms.dingtalk("100"+"号码",webhook)
|