#!/usr/bin/env pythonphp
#coding:utf-8html
import smtplibpython
from email.mime.text import MIMEText # 導入MIMEText類chrome
HOST = "smtp.126.com"瀏覽器
SUBJECT = u"官網流量數據報表"dom
TO = "to@qq.com"ide
FROM = "from@126.com"ui
# 建立一個MIMEText對象,分別指定HTML內容、類型(文本或或html)、字符編碼編碼
msg = MIMEText("""spa
<table width="800" border="0" cellspacing="0" cellpadding="4">
<tr>
<td><bgcolor="#CECFAD" height="20" style="font-size:14px"> 官網數據 <a href="monitor.domain.com">更多>></a></td>
</tr>
<tr>
<td bgcolor="#EFEBDE" height="100" style="font-size:13px">
1)日訪問量:<font color=red>152433</font> 訪問次數:23651 頁面瀏覽量:45123 點擊數:545122 數據流量:504Mb<br>
2)狀態碼信息<br>
500:105 404:3264 503:214<br>
3)訪客瀏覽器信息<br>
IE:50% firefox:10% chrome:30% other:10%<br>
4)頁面信息<br>
/index.php 42153<br>
/view.php 21451<br>
/login.php 5112<br>
</td>
</tr>
</table>""","html","utf-8")
msg['Subject'] = SUBJECT
msg['From'] = FROM
msg['To'] = TO
try:
server = smtplib.SMTP(HOST, "25")
server.starttls
server.login("from@126.com", "passwd")
server.sendmail(FROM, TO, msg.as_string())
server.quit()
print "郵件發送成功!"
except Exception, e:
print "失敗: "+str(e)