#coding: utf-8
import smtplib
import os.path
from email.Header import Header
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart

class notifyByEmail:
    def __init__(self, msgSubject, msgContent):
        self.msgSubject = msgSubject
        self.msgContent = msgContent

    def sendEmail(self):
        #msg = MIMEText(self.msgContent.encode('utf-8'), 'plain', 'utf-8')
        #msg['Subject'] = Header(self.msgSubject,'utf-8')
        #msg = MIMEText(self.msgContent)
        #msg['Subject'] = self.msgSubject
        msg = MIMEMultipart()
        msg_text = MIMEText(self.msgContent, _charset="gb2312")
        msg.attach(msg_text)
        msg['Subject'] = Header(self.msgSubject,'gb2312')
        s = smtplib.SMTP_SSL('smtp.fastmail.com:465')
        s.login('zzlyzq@fastmail.cn','gyq2hv3ewf4aplpz')
        #recvs = [ "zzlyzq@fastmail.cn","lina@sdgakj.com" ]
        recvs = [ "zzlyzq@fastmail.cn" ]
        s.sendmail('zzlyzq@fastmail.cn',recvs, msg.as_string())
        s.quit()
        print "done"
  • 调用
falconmail.notifyByEmail("监管平台连接60.216.86.28:27777端口发生变化",""" 发现异常,我们的期望是%s_%s, 但是找到了%s_%s """%(theServerAddressAndPort,myAddressAndPort,theTargetString[2],theTargetString[1])).sendEmail()
Copyright © opschina.org 2017 with zzlyzq@gmail.com all right reserved,powered by Gitbook该文件修订时间: 2017-07-26 17:40:05

results matching ""

    No results matching ""