Zabbix Mail Alert Python script code

Source: Internet
Author: User
Tags python script
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.