mail_host="xxx" #设置服务器 mail_postfix="xxx" #发件箱的后缀 mailto_list1=["xxxx"] def send_mail(to_list,sub,content): #to_list:收件人;sub:主题;content:邮件内容 msg = MIMEText(content,_subtype='html',_charset='utf-8') #创建一个实例,这里设置为html格式邮件 msg['Subject'] = sub #设置主题 msg['From'] = mail_postfix msg['To'] = ";".join(to_list) try: s = smtplib.SMTP() s.connect(mail_host) #连接smtp服务器 s.sendmail(mail_postfix, to_list, msg.as_string()) #发送邮件 s.close() return True except Exception, e: print str(e) return False def make_content(ws_result,count_text): content="<html><meta http-equiv='Content-Type' content='text/html; charset=utf-8'/><body><h3>统计信息 "+count_text+"</h3><h3>烦请检查设备到计费中央的网络传输是否正常:北京中央 223.202.52.23 bj-billing.chinacache.net;上海备点 101.251.97.200 sh-billing.chinacache.net </h3><br><table width='850' border='1'><tr><th scope='col'>id</th><th scope='col'>dev_id</th><th scope='col'>dev_name</th><th scope='col'>node_id</th><th scope='col'>filecount</th><th scope='col'>status</th><th scope='col'>bu</th><th scope='col'>applist</th></tr>" if(len(ws_result)>0): for index in range(len(ws_result)): content+="<tr>" content+="<td>"+str(ws_result[index][0])+"</td>" content+="<td>"+str(ws_result[index][1])+"</td>" content+="<td>"+str(ws_result[index][2])+"</td>" content+="<td>"+str(ws_result[index][3])+"</td>" content+="<td>"+str(ws_result[index][4])+"</td>" content+="<td>"+str(ws_result[index][5])+"</td>" content+="<td>"+ws_result[index][6].encode('utf-8')+"</td>" content+="<td>"+str(ws_result[index][7])+"</td>" content+="</tr>" return content