2eew 发表于 2016-1-18 10:09:22

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

# catqq_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:545122data_flow:504Mb<br>
      2)Status code information<br>
      &nbsp;&nbsp;500:105404:3264503: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)
#




测试:

# python qq_mail_html.py
send yes!
#





页: [1]
查看完整版本: python实现html格式的数据报邮件