发送邮件时禁用登录邮件

2024-04-26 10:30:17 发布

您现在位置:Python中文网/ 问答频道 /正文

当通过Flask Mail发送任何消息时,比如下面,带有mail.send(msg)的最后一行也会导致记录邮件头和内容。你知道吗

Message("Hello", sender="from@example.com", recipients=["to@example.com"])
msg.body = 'anything'
mail.send(msg)

由于我的邮件可能包含敏感信息,我想完全禁用此日志记录。但是,在使用日志模块时,我找不到为Flask Mail配置的记录器。你知道吗

如何禁用登录邮件?你知道吗


Tags: fromcomsend消息flask内容messagehello
1条回答
网友
1楼 · 发布于 2024-04-26 10:30:17

我想出来了:

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

任何输出现在都被抑制。你知道吗

相关问题 更多 >