#!/usr/bin/env python
# coding=utf8
import smtplib,sys
from email.mime.text import MIMEText
myhost = "smtp.qq.com"
myport = "465"
myuser = "xxx"
mypasswd = "xxx" smtp 密码;
mypostfix= "qq.com"
froms = "xxxx@qq.com"
def Sendmail(to,subject,content):
sender = "zabbix 3.4 报警"+"<"+myuser + "@" +mypasswd+">"
msg = MIMEText(content,"plain","utf=8")
msg["Subject"] = subject
msg["From"] = sender
msg["To"] = to
try:
se = smtplib.SMTP_SSL(myhost,myport)
se.login(froms,mypasswd)
se.sendmail(sender,to,msg.as_string())
se.close()
except Exception as e:
print(str(e))
return False
if __name__ == "__main__":
Sendmail(sys.argv[1],sys.argv[2],sys.argv[3])
转载于:https://blog.51cto.com/breaklinux/2167120