1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
import smtplib import email.mime.multipart import email.mime.text import sys
data = open("/tmp/slow-select.txt") f = data.read() data.close()
SMTP_SERVER = "smtpdm.aliyun.com"
FROM = 'notify@automail.1dailian.com'
PWD = 'MarkZhaofadan001'
PORT = 465
TO = str("408128151@qq.com")
THEME = str("PHP2-MySQL慢日志分析")
CONTEENT = str(f) def sendmail(SMTP_SERVER,PORT,FROM,PWD,msg): try: smtp = smtplib.SMTP_SSL() smtp.connect(SMTP_SERVER,PORT) smtp.login(FROM, PWD) smtp.sendmail(FROM, TO, msg.as_string()) smtp.quit() except smtplib.SMTPConnectError, e: print '邮件发送失败,连接失败:', e.smtp_code, e.smtp_error except smtplib.SMTPAuthenticationError, e: print '邮件发送失败,认证错误:', e.smtp_code, e.smtp_error except smtplib.SMTPSenderRefused, e: print '邮件发送失败,发件人被拒绝:', e.smtp_code, e.smtp_error except smtplib.SMTPRecipientsRefused, e: print '邮件发送失败,收件人被拒绝:', e.smtp_code, e.smtp_error except smtplib.SMTPDataError, e: print '邮件发送失败,数据接收拒绝:', e.smtp_code, e.smtp_error except smtplib.SMTPException, e: print '邮件发送失败, ', e.message except Exception, e: print '邮件发送异常, ', str(e) if __name__ == '__main__': server = SMTP_SERVER port = PORT msg = email.mime.multipart.MIMEMultipart() msg['Subject'] = THEME msg['From'] = FROM msg['To'] = TO user = FROM pwd = PWD txt = email.mime.text.MIMEText(CONTEENT, _subtype='plain', _charset='UTF-8') msg.attach(txt) sendmail(server,port,user,pwd,msg)
|