前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 通过qq邮箱发送磁盘监控告警

python 通过qq邮箱发送磁盘监控告警

作者头像
葫芦
发布2019-04-17 14:54:54
7350
发布2019-04-17 14:54:54
举报
文章被收录于专栏:葫芦葫芦葫芦

python通过qq邮箱发送磁盘监控告警

#encoding=gb2312
'''
@author: wangzi
'''
import psutil
import smtplib
from email.mime.text import MIMEText


mailto_list = ['277215243@qq.com']
mail_host = 'smtp.qq.com'
mail_user = '***@qq.com'
mail_pass = '***'
mail_postfix='qq.com'

def send_mail(to_list,sub,content):
    me = '王梓'+'<'+mail_user+'@'+mail_postfix+'>'
    msg = MIMEText(content,_subtype = 'html',_charset='gb2312')
    msg['Subject'] = sub
    msg['From'] = me
    msg['to'] = ';'.join(to_list)

    try:
        server = smtplib.SMTP()
        server.connect(mail_host)
        server.login(mail_user,mail_pass)
        server.sendmail(me,to_list,msg.as_string())
        server.close()
        return True
    except Exception as e:
        print (e)
        return False
if __name__ == '__main__':
    mainhtml = open('percent.html').read()
    fordivpercent = open('fordivpercent.html').read()
    percentcss = open('percent.css', encoding='utf-8').read()
    dist_str = ''
    for ps in psutil.disk_partitions():
        dist_str+= fordivpercent.format(ps[1],psutil.disk_usage(ps[1])[3])
    dist_str += fordivpercent.format('/Users/wangzi/www', psutil.disk_usage('/Users/wangzi/www')[3])
    mailhtml = mainhtml.format(percentcss, dist_str)
    print(mailhtml)
    if send_mail(mailto_list, '磁盘监控', mailhtml):
        print('发送成功')
    else:
        print('发送失败')
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016/11/07 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档