python 发送邮件函数模块

时间:2024-04-23 22:05:06

发送邮件函数功能

 #!/usr/bin/env python
# -*- coding:utf-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
def email(message):
msg = MIMEText(message, 'plain', 'utf-8')
msg['From'] = formataddr(["大大", 'n1049759078@126.com'])
msg['To'] = formataddr(["小小", '2721593215@qq.com'])
msg['Subject'] = "鬼谷报警系统" server = smtplib.SMTP("smtp.126.com", 25)
server.login("n1049759078@126.com", "密码")
server.sendmail('n1049759078@126.com', ['2721593215@qq.com', ], msg.as_string())
server.quit()
if __name__ == '__main__':
cpu = 100
disk = 80
ram = 60
for i in range(1):
if cpu > 80:
al = u"cpu出问题了"
email(al)
if disk > 70:
al = u"disk出问题了"
email(al)
if ram > 90:
al = u"ram出问题了"
email(all)