继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

zabbix用python发送邮件

森栏
关注TA
已关注
手记 385
粉丝 102
获赞 476

!/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("%s\n%s\n%s\n"%(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])

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP