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

[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 = "[email protected]"    

FROM = "[email protected]"      

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("[email protected]","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]# 




wKiom1aYktjSfw8GAAD5wRXklKA347.png

你可能感兴趣的:(python,邮件,监控,报警)