发送邮件函数功能
1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*- 3 import smtplib 4 from email.mime.text import MIMEText 5 from email.utils import formataddr 6 def email(message): 7 msg = MIMEText(message, 'plain', 'utf-8') 8 msg['From'] = formataddr(["大大", 'n1049759078@126.com']) 9 msg['To'] = formataddr(["小小", '2721593215@qq.com']) 10 msg['Subject'] = "鬼谷报警系统" 11 12 server = smtplib.SMTP("smtp.126.com", 25) 13 server.login("n1049759078@126.com", "密码") 14 server.sendmail('n1049759078@126.com', ['2721593215@qq.com', ], msg.as_string()) 15 server.quit() 16 if __name__ == '__main__': 17 cpu = 100 18 disk = 80 19 ram = 60 20 for i in range(1): 21 if cpu > 80: 22 al = u"cpu出问题了" 23 email(al) 24 if disk > 70: 25 al = u"disk出问题了" 26 email(al) 27 if ram > 90: 28 al = u"ram出问题了" 29 email(all)