This article describes the Zabbix Mail alert Python script code
#!/usr/bin/python#-*-coding:utf-8-*-"" "Zabbix SMTP Alert script from Qq.auth:json" "" Import sysimport emailimport Smtpl Ibimport osfrom email.mime.text Import mimetextfrom email.mime.multipart import mimemultipart# mail send list to who #mailto_ list=["Winson.zhou@gmail", "zhoufr@youqudao.com"] #设置服务器, user name, password mail_host= "smtp.exmail.qq.com" mail_user= " 123456789@qq.com "mail_pass=" 123456789 "mail_postfix=" qq.com "#定义send_mail函数def Send_mail (to_list,sub,content): ' To_list: To whom sub: topic Content: Send_mail ("123456789@qq.com", "sub", "Contents") "#if not Isinstance (sub,unic ODE): #sub = Unicode (sub) address=mail_user msg = Mimetext (Content,format, ' utf-8 ') msg["Accept-language"]= "zh- CN "msg[" Accept-charset "]=" Iso-8859-1,utf-8 "msg[' Subject '] = Sub msg[' from ') = Address msg[' to '] =to_list Try:s = Smtplib. Smtp_ssl (mail_host,port=465) #s. Connect (mail_host) s.login (Mail_user,mail_pass) s.sendmail (address, t O_list, msg.as_string ()) S.close () return True except Exception, E:print str (e) return falseif __name__ = = ' __main__ ': Send_mail (Sys.argv[1], sys.argv[2], sys.argv[3])
Test method:
Executed under the current script directory
Python Script name Sender mailbox message header message content
Python sendemail.py test@qq.com Zabbix zabbixcontent