[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>
500:105 404:3264 503:214<br>
3)user information<br>
IE:50% firefox:10% chrome:30% other:10%<br>
4)page information<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()
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]#