Zabbix Python mail script code

Source: Internet
Author: User
This article describes the Zabbix Python mail script code

#!/usr/bin/env python#-*-coding:utf-8-*-# author:heyic.m@gmail.com# date:2017-03-10# Zabbix alarm script, set up multiple Outbox randomly send import    Sysimport smtplibfrom email.mime.text Import mimetextfrom email.utils import formataddrimport random # Sender Dictionary sender = { ' sender_139 ': {' smtp ': ' smtp.139.com ', ' user ': ' 136xxxxxx@139.com ', ' Pass ': ' Pass '}, ' Sender_ 163 ': {' smtp ': ' smtp.163.com ', ' user ': ' xxxxxxxxxxxx@163.com ', ' Pass ': ' Pass '}, ' Sender_comp '         : {' smtp ': ' 192.168.193.27 ', ' user ': ' xxxxxxxxxxx@local.com ', ' Pass ': ' Pass '}, ' Sender_qq ': { ' SMTP ': ' smtp.qq.com ', ' user ': ' xxxxxxxxxxx@qq.com ', ' Pass ': ' Pass '} # Random get sender Mailbox Def get_sender (): Send_server_list = [] For each of sender:send_server_list.append (each) index = Random.randrange (Len (s Ender)) return Sender[send_server_list[index] # recipient, message header, message body, sender def send_mail (to_list, subject, msg_content, sender) : # third-party mail server and authentication Mail_host = sender[' smtp '] mail_user = sender[' user '] Mail_pass = sender[' pass ') # message content msg = Mimetext (msg_content,  ' Plain ', ' utf-8 ') msg[' from '] = formataddr ([' Alarm mail ', mail_user]) # sender shows msg[' to ' = formataddr ([' Me ', To_list]) # The recipient displays msg[' Subject ' = Subject # send try:server = Smtplib. SMTP (mail_host) server.login (Mail_user, Mail_pass) server.sendmail (Mail_user, [To_list], msg.as_string ( )) Server.quit () except Smtplib. Smtpexception as E:print (e) if __name__ = = ' __main__ ': Sender = Get_sender () # Zabbix alarm requires three parameters, order recipient, message header, mail Article # send_mail (' yic.he@szpcg.com ', ' Random send Test ', ' random send test, haha la ha ', sender) Send_mail (sys.argv[1], sys.argv[2], sys.argv[3], Sender
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.