问题描述
我一直在关注教程 - https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-vii-error-handling,但无法使用我的 Gmail 帐户进行电子邮件日志记录。
在我的 init.py 中,我有:
import logging
from logging.handlers import SMTPHandler
# ...
if not app.debug:
if app.config['MAIL_SERVER']:
auth = None
if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
auth = (app.config['MAIL_USERNAME'],app.config['MAIL_PASSWORD'])
secure = None
if app.config['MAIL_USE_TLS']:
secure = ()
mail_handler = SMTPHandler(
mailhost=(app.config['MAIL_SERVER'],app.config['MAIL_PORT']),fromaddr='no-reply@' + app.config['MAIL_SERVER'],toaddrs=app.config['ADMINS'],subject='Microblog Failure',credentials=auth,secure=secure)
mail_handler.setLevel(logging.ERROR)
app.logger.addHandler(mail_handler)
并设置环境变量
export MAIL_SERVER=smtp.gmail.com
export MAIL_PORT=587
export MAIL_USE_TLS=1
export MAIL_USERNAME=<your-gmail-username>
export MAIL_PASSWORD=<your-gmail-password>
我在我的 gmail 帐户上设置了“使用安全性较低的应用程序”并使用了普通密码,但我无法从本地计算机(在 localhost:5000 上运行)上的测试应用程序获得连接。我查看了 mail_handler 对象,我看到:
<SMTPHandler (ERROR)>
因此在应用程序启动时没有建立连接。我花了一个小时来更改端口(587 和 465)等内容。设置新帐户。
如果有人有任何有用的想法,我将不胜感激。
谢谢
马丁
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)