flask-mail gmail: connection refused

戏子无情 提交于 2019-11-28 07:46:28

As far as I can tell there is nothing wrong with this configuration. The only problem is that your application is not using it. You should update configuration before you initialize Mail:

app = Flask(__name__)

app.config.update(dict(
    DEBUG = True,
    MAIL_SERVER = 'smtp.gmail.com',
    MAIL_PORT = 587,
    MAIL_USE_TLS = True,
    MAIL_USE_SSL = False,
    MAIL_USERNAME = 'my_username@gmail.com',
    MAIL_PASSWORD = 'my_password',
))

mail = Mail(app)

In addition to zero323's answer, adding the configuration before creating a Mail object should help, but if it gives an SMTPAuthentication error with a gmail server, then just for testing purpose one may allow less secure apps to login for a while - https://myaccount.google.com/security#signin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!