|
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#该邮件功能只是发送基本的文本内容,不带任何附件与图片,发送格式是以html发送的
import smtplib
from email.mime.text import MIMEText
mailto_list=['745292907@qq.com','guozheng_li@quantone.com']
mail_host="smtp.163.com" #设置服务器
mail_user="XXX@XX.com" #用户名
mail_pass="XXXXXX" #口令
mail_postfix="163.com" #发件箱的后缀
#HTML代码段
h = """
<table width="800" border="0" cellspacing="0" cellpaddind="4">
<tr>
<td bgcolor="#CECFAD" height="20" style="font-size:14px">*假官网数据<a href=" </tr>
<tr>
<td bgcolor="#EFEBDE" height="100" style="font-size:13px">
1)日访问量:<font color=red>152433</font><br>
2)状态码信息<br>
500:105 404:3264 503:214</br>
3)访问浏览器信息<br>
IE:50% firefox:10% chrome:30% other:10%</br>
</td>
</tr>
</table>"""
def send_mail(to_list,sub,content):
me="163"+"<"+mail_user+"@"+mail_postfix+">"
msg = MIMEText(content,'html','utf-8')
#固定格式
msg['Subject'] = sub #主题
msg['From'] = me #发件人
msg['To'] = ";".join(to_list) #收件人列表
try:
server = smtplib.SMTP()
server.connect(mail_host) #建立连接
server.login(mail_user,mail_pass) #登录邮箱
server.sendmail(me, to_list, msg.as_string())#发送邮箱
server.close() #关闭连接
return True
except Exception, e: #发送异常后,将异常状态打印出来
print str(e)
return False
if __name__ == '__main__':
#真正执行的地方!
if send_mail(mailto_list,"hello",h): #参数:收件人列表,主题,内容
print "发送成功"
else:
print "发送失败"
|
|