zabbix发送邮件py脚本
#!/usr/bin/env python#coding: utf-8
import smtplib
import sys,os
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
def sendmail(receiver,subject,content):
sender = 'monitor@company.com'
receiver = sys.argv
subject = sys.argv
smtpserver = 'smtp.exmail.qq.com'
username = 'monitor@company.com'
password = 'monitor_password'
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = subject
msgRoot['From'] = ''
msgRoot['To'] = receiver
msgText = MIMEText(content)
#msgText = MIMEText(content,'html','utf-8')
msgRoot.attach(msgText)
smtp = smtplib.SMTP()
smtp.connect(smtpserver)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msgRoot.as_string())
smtp.quit()
if __name__ == '__main__':
if len(sys.argv) < 3:
print '%s addres subject msg' % sys.argv
sys.exit()
sendmail(sys.argv,sys.argv,sys.argv)
页:
[1]