zabbix用python发送邮件

2020-01-10 11:37:19 浏览数 (1)

代码语言:javascript复制
!/usr/bin/python
coding: utf-8
import smtplib
import sys
from email.mime.text import MIMEText
_user = "12345678@qq.com"
_pwd  = "授权码"
_to   = "123456789@163.com"
def send_mail(to,subject,contain):
msg = MIMEText(contain)
msg["Subject"] = subject
msg["From"]    = _user
msg["To"]      = to
try:
s = smtplib.SMTP_SSL("smtp.qq.com", 465)
s.login(_user, _pwd)
s.sendmail(_user, to, msg.as_string())
s.quit()
with open('/tmp/zabbix.log', 'w') as f:
f.write("%sn%sn%sn"%(to,subject,contain))
print "Success!"
except smtplib.SMTPException,e:
print "Falied,%s"%e
if name == "main":
send_mail(sys.argv[1], sys.argv[2], sys.argv[3])

0 人点赞