通过 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 中的登录?
最佳答案
想出了这个:
Flask-Mail 使用 Python 的 smtplib发送邮件。 smtplib 不使用 logging 模块,但它会将调试信息打印到 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
现在抑制任何输出。
关于python - 发送消息时禁用登录 Flask-Mail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58309600/