#!/usr/bin/python

#_*_ coding:utf-8 _*_

import smtplib

from email.mime.text import MIMEText

from email.header import Header

from smtplib import SMTP_SSL

import sys


smtpaddr='smtp.163.com'

myemail='邮箱地址'

password='----------'

#f=open('/usr/local/zabbix/.passwd','r')

#password=f.readline().strip()


recvmail=sys.argv[1]

subject=sys.argv[2]

content=sys.argv[3]

msg=MIMEText('''%s'''%(content),"plain","utf-8")

msg["Subject"]=Header(subject,'utf-8').encode()

msg["From"]=myemail

msg["To"]=recvmail

try:

 smtp=SMTP_SSL(smtpaddr)

 smtp.login(myemail,password)

 smtp.sendmail(myemail,recvmail.split(','),msg.as_string())

 smtp.quit()

 print("success")

except Exception as e:

 print("fail:"+str(e))


手动测试:

/usr/local/zabbix/alertscripts/zabbix_sendmail.py 接收邮箱地址 '标题' '内容'