python代码邮件发送增加次数判断,python邮件发送,1.[python代码邮
python代码邮件发送增加次数判断,python邮件发送,1.[python代码邮
1.[python代码邮件发送增加次数判断代码][Python]
# -*- coding:utf-8 -*-'''sendmail模块判断文件名记录次数发送告警check_key模块记录文件名次数至字典,返回查询文件名对应的次数read_file模块读取文件至字典write_file模块将最新记录更新至文件''' import smtplibfrom email.mime.text import MIMETextimport sysclass MailModel: def __init__(self): self.mail_host = "smtp.126.com" self.mail_user = "lanfeng007" self.mail_pass = "xxxxxxxxxx" self.postfix = "126.com" def write_file(self,what): with open("user.txt", "w") as f: for key,value in what.items(): f.writelines(str(key)+','+str(value)+'\n') f.flush() def read_file(self): with open("user.txt", "r") as f: listStu = {} for k,v in (l.split(',') for l in f) : listStu[k.strip()]=int(v.strip()) return listStu def check_key(self,content): listStu=self.read_file() if content in listStu: listStu[content] = int(listStu[content]) + 1 self.write_file(listStu) return listStu[content] else: listStu[content] = 1 self.write_file(listStu) return listStu[content] def send_mail(self, user_list, sub, content): ''' 根据check_key判断文件名记录次数 大于3次则直接跳过发送输出信息 ''' if self.check_key(content) > 2: print '发送次数超过3次' else: me = "hello"+"<"+self.mail_user+"@"+self.postfix+">" msg = MIMEText(content, _subtype = 'html', _charset = 'utf-8') msg['Subject'] = sub msg['From'] = me msg['To'] = ';'.join(user_list) try: server = smtplib.SMTP() server.connect(self.mail_host) server.login(self.mail_user, self.mail_pass) server.sendmail(me, user_list, msg.as_string()) server.close() print '发送成功' except Exception, e: print str(e) print '发送失败,请检查'if __name__=='__main__': mailuser_list=["369134@qq.com", "xuheng@tyread.com"] title = sys.argv[1] content = sys.argv[2] mail = MailModel() mail.send_mail(mailuser_list,title, content) #mail.send_mail(mailuser_list,'告警文件','/fiodata/DataFiles/outside/NGLogHour/2015-12-09//nginxxf/2015-12-09_192.168.10.194_14.log.zip')
2.[图片] 1111.png
3.[图片] 2222.png
编橙之家文章,
相关内容
- python查找1~n以内包括n素数,python素数,<python查找1~
- python解数学题之分解质因数,python质因数,<python解数
- Python代码不用怕复制粘贴,python代码不用怕,<Python代
- 简单发送飞信的python代码,python代码,简单发送飞信的
- python论坛自动签到用bs4模块,python签到bs4模块,python论坛
- python微信公众平台模板消息发送功能,python公众,pytho
- 几百行代码做出http/https代理服务器,几百行https,一个几
- 用python解析风行网vip电影播放地址解析,pythonvip,用py
- python初学者的猜数字游戏,python初学者猜数字,python初学
- python统计nginx日志ip和流量,pythonnginx日志ip,python统计
评论关闭