码迷,mamicode.com
首页 > 编程语言 > 详细

python实现html格式的数据报邮件

时间:2016-01-15 17:59:11      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:python 报警 监控 邮件

[root@www smtplib]# cat  qq_mail_html.py

#!/usr/bin/env python


import smtplib  

from email.mime.text import MIMEText    #??MIMEText?  

 

HOST = "smtp.163.com"    

SUBJECT = "Website traffic data tables"    

TO = "961769710@qq.com"    

FROM = "15517707935@163.com"      

msg = MIMEText("""      

                

    <table width="800" border="0" cellspacing="0" cellpadding="4"> 

      <tr> 

        <td bgcolor="#CECFAD" height="20" style="font-size:14px">Website data  <a href="monitor.domain.com">more>></a></td> 

      </tr> 

      <tr> 

        <td bgcolor="#EFEBDE" height="100" style="font-size:13px"> 

        1)day_traffic:<font color=red>152433</font>  traffic:23651 page_traffic:45123 click:545122  data_flow:504Mb<br> 

        2)Status code information<br> 

        &nbsp;&nbsp;500:105  404:3264  503:214<br> 

        3)user information<br> 

        &nbsp;&nbsp;IE:50%  firefox:10% chrome:30% other:10%<br> 

        4)page information<br> 

        &nbsp;&nbsp;/index.php 42153<br> 

        &nbsp;&nbsp;/view.php 21451<br> 

        &nbsp;&nbsp;/login.php 5112<br> 

        </td> 

      </tr> 

    </table>""","html","utf-8")  

msg[‘Subject‘] = SUBJECT      

msg[‘From‘]=FROM     

msg[‘To‘]=TO      

try:  

    server = smtplib.SMTP()      

    server.connect(HOST,"25")    

    server.starttls()     

    server.login("15517707935@163.com","kptgpcamuyzxodvo")      

    server.sendmail(FROM, TO, msg.as_string())     

    server.quit()      

    print "send yes!"  

except Exception, e:  

    print "lose:"+str(e) 

[root@www smtplib]# 





测试:


[root@www smtplib]# python qq_mail_html.py 

send yes!

[root@www smtplib]# 




技术分享

本文出自 “积少成多” 博客,请务必保留此出处http://9399369.blog.51cto.com/9389369/1735319

python实现html格式的数据报邮件

标签:python 报警 监控 邮件

原文地址:http://9399369.blog.51cto.com/9389369/1735319

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!