发布于 2018-01-30 04:28:12 | 107 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Python多线程编程,程序狗速度看过来!

Python编程语言

Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。


这篇文章主要介绍了python使用logging模块发送邮件代码示例,具有一定借鉴价值,需要的朋友可以参考下

logging模块不只是能记录log,还能发送邮件,使用起来非常简单方便


#coding=utf-8 
''''' 
Created on 2016-3-21 
 
@author: Administrator 
''' 
import logging, logging.handlers 
class EncodingFormatter(logging.Formatter): 
 def __init__(self, fmt, datefmt=None, encoding=None): 
  logging.Formatter.__init__(self, fmt, datefmt) 
  self.encoding = encoding 
 def format(self, record): 
  result = logging.Formatter.format(self, record) 
  if isinstance(result, unicode): 
   result = result.encode(self.encoding or 'utf-8') 
    
  return result 
 
#zhangdongsheng@itouzi.com 
errlog = logging.getLogger() 
sh = logging.handlers.SMTPHandler("smtp.163.com", 'xigongda200608@163.com', '381084992@qq.com', 
    "logging from my app", 
    credentials=('xigongda200608', 'password'), 
    secure=()) 
errlog.addHandler(sh) 
sh.setFormatter(EncodingFormatter('%(message)s', encoding='utf-8')) 
errlog.error(u'追加文件时出错') 

总结

以上就是本文关于python使用logging模块发送邮件代码示例的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务