34fw 发表于 2015-1-14 08:29:44

检查到apache和php有错误发送邮件

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import smtplib,sys
import string
import email.MIMEText
from email.mime.text import MIMEText
reload(sys)
sys.setdefaultencoding('utf8')
HOST = "smtp.126.com"
TO = ['xxxxxx','xxxxxx']
FROM = "xxxxxxx"
text = sys.argv
print text
if text.count('Asia') != 0:
    subject = "注意php有错误日志"
else:
    subject = "注意apache有错误日志"
if not isinstance(subject,unicode):
      subject = unicode(subject)

msg = MIMEText(text,format,'utf-8')
if not isinstance(subject,unicode):
    subject = unicode(subject)

msg['Subject'] = subject
msg['From'] = FROM
msg["Accept-Language"]="zh-CN"
msg["Accept-Charset"]="ISO-8859-1,utf-8"

def sendmail():
    try:
      server = smtplib.SMTP()
      server.connect(HOST,"25")
      server.login("xxxxxxx","xxxxxxxxx")
      server.sendmail(FROM, TO, msg.as_string())
      server.quit()
      print "成功"
    except Exception, e:
      print "失败:" + str(e)
sendmail()



页: [1]
查看完整版本: 检查到apache和php有错误发送邮件