This article introduces zabbix email warning python script code
#! /Usr/bin/python #-*-coding: UTF-8-*-"Zabbix SMTP Alert script from qq. auth: json "" import sysimport emailimport smtplibimport osfrom email. mime. text import MIMETextfrom email. mime. multipart import MIMEMultipart # Mail sending list to whom # mailto_list = ["winson. zhou @ gmail "," zhoufr@youqudao.com "] # set the server, username, password mail_host = "smtp.exmail.qq.com" mail_user = "123456789@qq.com" mail_pass = "123456789" mail_postfix = "qq.com" # define the send_mail function def send_mail (to_list, sub, content ): '''to_list: to whom sub: topic content: content send_mail ("123456789@qq.com", "sub", "content") ''' # if not isinstance (sub, unicode ): # 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 ['subobject'] = 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, to_list, msg. as_string () s. close () return True expect T Exception, e: print str (e) return Falseif _ name _ = '_ main _': send_mail (sys. argv [1], sys. argv [2], sys. argv [3])
Test method:
Run the following command in the current script Directory:
Python script name sender email Mail title email content
Python sendemail. py test@qq.com zabbix zabbixcontent
The above is the details of the zabbix email warning python script code. For more information, see other related articles in the first PHP community!