zabbix 4.2 发送警告邮件Python脚本

it2022-05-05  120

#!/usr/bin/env python#-*- coding: UTF-8 -*-import os,sysimport getoptimport smtplibfrom email.MIMEText import MIMETextfrom email.MIMEMultipart import MIMEMultipartfrom subprocess import *def sendqqmail(username,password,mailfrom,mailto,subject,content): gserver = 'smtp.xx.com' gport = 25 try: msg = MIMEText(content,'plain','utf-8') msg['from'] = mailfrom msg['to'] = mailto msg['Reply-To'] = mailfrom msg['Subject'] = subject smtp = smtplib.SMTP(gserver, gport) smtp.set_debuglevel(0) smtp.ehlo() smtp.login(username,password) smtp.sendmail(mailfrom, mailto, msg.as_string()) smtp.close() except Exception,err: print "Send mail failed. Error: %s" % errdef main(): to=sys.argv[1] subject=sys.argv[2] content=sys.argv[3] sendqqmail('xx@xx.com','password','xx@xx.com',to,subject,content)

if __name__ == "__main__": main()

 

#注 :在本人测试环境已经成功,因为不是自己写的,所以有问题还请百度自行解决。

转载于:https://www.cnblogs.com/cnqfz/p/11170624.html


最新回复(0)