python使用logging模块发送邮件代码示例
2018-01-18 15:09
1031 查看
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模块发送邮件代码示例的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!
您可能感兴趣的文章:
相关文章推荐
- Python(2.7.x)使用SMTP发送邮件的简单示例
- 二种python发送邮件实例讲解(python发邮件附件可以使用email模块实现)
- Python_使用smtplib和email模块发送邮件
- python logging 模块完整使用示例
- python_使用email模块发送简单邮件
- python使用smtplib模块通过gmail实现邮件发送的方法
- python中使用smtplib和email模块发送邮件实例
- nodejs模块nodemailer基本使用-邮件发送示例(支持附件)
- Python实现邮件的批量发送的示例代码
- Python_使用smtplib和email模块发送邮件
- 使用spring mail发送html邮件的示例代码
- 二种python发送邮件实例讲解(python发邮件附件可以使用email模块实现)
- Python编程使用tkinter模块实现计算器软件完整代码示例
- Android Java使用JavaMail API发送和接收邮件的代码示例
- Python_使用smtplib和email模块发送邮件
- Python使用pickle模块存储数据报错解决示例代码
- Python_使用smtplib和email模块发送邮件
- Python3 使用smtplib和email模块发送邮件
- 使用python的smtp模块发送邮件
- python 使用Django 的 邮件模块 发送邮件