#!/usr/bin/env python#coding=gb2312 #设置中文字体编码(根据你系统环境配置)#auther = shaw #ver = 0.8import smtplibimport sysimport email.mime.textfrom email.Header import Header#邮件主体mail_username = 'admin@sina.cn' #发送人地址mail_password = 'ad123456' #发送人密码from_addr = mail_usernameto_addrs = ['admin@ztgame.com','shaw@sina.com'] #接受者地址(群邮件)HOST = 'smtp.sina.cn' #服务器发邮件地址PORT = 25 #服务器发邮件端口smtp = smtplib.SMTP()print 'connecting ...'#smtp.set_debuglevel(1) #不显示debug log输出try: print smtp.connect(HOST,PORT)except: print '\033[31;2mCONNECT ERROR \033[0m****'smtp.starttls() # 启用ssl加密try: print 'loginning ...' smtp.login('admin@sina.cn','ad123456')except: print '\033[31;2mLOGIN ERROR \033[0m****'#邮件内容msg = email.mime.text.MIMEText("""Dear shaw: 警告:/tmp/log.txt备份发生错误。 """_subtype='plain', _charset='gb2312') #指定邮件内容字体编码msg['From'] = from_addrmsg['To'] = ';'.join(to_addrs)msg['Subject']=Header('log.txt日志备份出错', charset='gb2312') # 邮件主题print msg.as_string()smtp.sendmail(from_addr,to_addrs,msg.as_string())smtp.quit()