python 发送邮件函数模块

发送邮件函数功能

 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(["大大", 'xxxxx@126.com'])
 9     msg['To'] = formataddr(["小小", 'xxxx@qq.com'])
10     msg['Subject'] = "鬼谷报警系统"
11 
12     server = smtplib.SMTP("smtp.126.com", 25)
13     server.login("xx@126.com", "密码")
14     server.sendmail('xx@126.com', ['xx@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)

 

posted @ 2016-12-04 15:11  程序员同行者  阅读(832)  评论(0编辑  收藏  举报