if isinstance(value, str): for encoding in ("utf-8", "gbk", "cp936", sys.getdefaultencoding(), "gb2312", "gb18030", "big5", "latin-1", "ascii"): try: value = value.decode(encoding) break # 如果上面这句执行没错,说明是这种编码 except: pass # 其它类型 return value if __name__ == '__main__': #错误信息邮件通知配置 htmlStyle=getStyleStr() htmlHeah=getTableHeadStr() htmlTable=dealData() htmlTail=getTailStr() host = "smtp.126.com" user = "******" password = "******" fro = u"杨阳<*****@*****.**>" #这里可以任意设置,收到信后,将按照设置显示收件人 mail_to_list = ["*****@*****.**"] # 收信人,发多个人需要用列表,只用字符串则只发第一个 subject = u"附件测试" charset = 'utf-8' #text = to_unicode(text).encode(charset) #text = htmlStyle+htmlHeah+htmlTable+htmlTail text = to_unicode(htmlStyle).encode(charset)+to_unicode(htmlHeah).encode(charset)+to_unicode(htmlTable).encode(charset)+to_unicode(htmlTail).encode(charset) #print text files = [u"C:\\Users\\Administrator\\Desktop\\sendMail\\file\\Business_file.csv"] res = send_mail(host, user, password, fro, mail_to_list, subject, text, files=files) if res:
from dealData import * data = '42 4d 00 1C 00 99 00 E0 01 11 00 65 00 95 00 B6 67 41 1E 09 06 75 00 AA 00 2C 00 12 71 00 06 89' #data = '71 00 06 f9 42 4d 00 1c 00 70 00 9f 00 bf 00 4a 00 69 00 7f 42 84 12 b3 03 b2 00 69 00 18 00 0a' #data = 'hhhhhhh' dealData(data)