Zabbix Mail Alert Python script

Source: Internet
Author: User
Tags python script

#!/usr/bin/python

#-*-Coding:utf-8-*-

"""

Zabbix SMTP Alert script from QQ.

Auth:json

"""

Import Sys

Import Email

Import Smtplib

Import OS

From Email.mime.text import Mimetext

From Email.mime.multipart import Mimemultipart

#邮件发送列表, who are you sending?

#mailto_list =["[email protected]", "[email protected]"]

#设置服务器, user name, password

Mail_host= "Smtp.exmail.qq.com"

mail_user= "[Email protected]"

Mail_pass= "123456789"

mail_postfix= "Qq.com"

#定义send_mail函数

def send_mail (to_list,sub,content):

‘‘‘

To_list: Who to send

Sub: Subject

Content: Contents

Send_mail ("[Email protected]", "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[' 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, to_list, msg.as_string ())

S.close ()

Return True

Except Exception, E:

Print str (e)

Return False

if __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 [email protected] Zabbix zabbixcontent

This article is from the "joy1991" blog, make sure to keep this source http://joy1991.blog.51cto.com/8359406/1903608

Zabbix Mail Alert Python script

Related Article

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.