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