码迷,mamicode.com
首页 > 编程语言 > 详细

zabbix发送邮件python脚本

时间:2016-08-30 18:10:12      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

#!/usr/bin/python 
# coding:utf-8
# 适用于python 2.x,解决python发送邮件乱码问题
 
import smtplib 
from email.mime.text import MIMEText 
import sys 
 
mail_host = smtp.mail.com 
mail_user = yourmail@mail.com 
mail_pass = passwd 
mail_postfix = mail.com 
 
def send_mail(to_list,subject,content): 
    me = mail_user+"<"+mail_user+"@"+mail_postfix+">" 
    # 增加 _charset="utf-8" ,使MIMEText使用utf-8编码,避免中文乱码
    msg = MIMEText(content,_charset="utf-8")
    msg[Subject] = subject 
    msg[From] = me 
    msg[to] = to_list 
    try: 
        s = smtplib.SMTP() 
        s.connect(mail_host) 
        s.login(mail_user,mail_pass) 
        s.sendmail(me,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]) 

 

zabbix发送邮件python脚本

标签:

原文地址:http://www.cnblogs.com/coolking/p/5822736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!