zabbix e-mail alerts python script

#!/usr/bin/python

#_*_ coding:utf-8 _*_

import smtplib

from email.mime.text import MIMEText

from email.header import Header

from smtplib import SMTP_SSL

import sys


smtpaddr='smtp.163.com'

myemail = 'mail address'

password='----------'

#f=open('/usr/local/zabbix/.passwd','r')

#password=f.readline().strip()


recvmail=sys.argv[1]

subject=sys.argv[2]

content=sys.argv[3]

msg=MIMEText('''%s'''%(content),"plain","utf-8")

msg["Subject"]=Header(subject,'utf-8').encode()

msg["From"]=myemail

msg["To"]=recvmail

try:

 smtp=SMTP_SSL(smtpaddr)

 smtp.login(myemail,password)

 smtp.sendmail(myemail,recvmail.split(','),msg.as_string())

 smtp.quit()

 print("success")

except Exception as e:

 print("fail:"+str(e))


Manual testing:

/usr/local/zabbix/alertscripts/zabbix_sendmail.py receiving the e-mail address 'title' 'content'


Guess you like

Origin blog.51cto.com/6300167/2422044