当通过Flask-Mail发送任何消息时,如下图所示,带有mail.send(msg)的最后一行也将导致邮件标题和内容被记录。
Message("Hello", sender="from@example.com", recipients=["to@example.com"])
msg.body = 'anything'
mail.send(msg)因为我的邮件可能包含敏感信息,所以我想完全禁用此日志记录。然而,在使用日志记录模块时,我找不到为Flask-Mail配置的记录器。
如何禁用Flask-Mail中的日志记录?
发布于 2019-10-10 16:02:56
解决了这个问题:
Flask-Mail使用Python的smtplib发送邮件。smtplib不使用日志记录模块,但它将调试信息打印到stderr。
smtplib包括以下方法:
def set_debuglevel(self, debuglevel):
"""Set the debug output level.
A non-false value results in debug messages for connection and for all
messages sent to and received from the server.
"""
self.debuglevel = debuglevel如果我们使用Flask-Mail,我们可以在初始化应用程序时设置这个变量,如下所示:
app = Flask(__name__)
mail = Mail(app)
app.extensions['mail'].debug = 0任何输出现在都会被抑制。
https://stackoverflow.com/questions/58309600
复制相似问题