def init_app(cls, app):
Config.init_app(app)
# email errors to the administrators
# setup Python's logging handler if Sentry's not used
if not cls.SENTRY_DSN_SECRET:
from logging.handlers import SMTPHandler
credentials = None
secure = None
if getattr(cls, 'MAIL_USERNAME', None) is not None:
credentials = (cls.MAIL_USERNAME, cls.MAIL_PASSWORD)
if getattr(cls, 'MAIL_USE_TLS', None):
secure = ()
mail_handler = SMTPHandler(
mailhost=(cls.MAIL_SERVER, cls.MAIL_PORT),
fromaddr=cls.MAIL_USERNAME,
toaddrs=[cls.APP_ADMIN_EMAIL],
subject=cls.APP_MAIL_SUBJECT_PREFIX + ' Application Error',
credentials=credentials,
secure=secure)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
评论列表
文章目录