zabbix郵件報警python腳本

#!/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

#郵件發送列表,發給哪些人

#mailto_list=["winson.zhou@gmail","[email protected]"]

#設置服務器,用戶名、密碼

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:發給誰

    sub:主題

    content:內容

    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])



測試方法:

在當前腳本目錄下執行

python 腳本名稱 發送人郵箱 郵件標題 郵件內容

python sendemail.py [email protected] zabbix zabbixcontent

本文出自 “joy1991” 博客,請務必保留此出處http://joy1991.blog.51cto.com/8359406/1903608


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章