flask-mail gmail: connection refused

前端 未结 2 601
灰色年华
灰色年华 2020-12-08 22:47

I\'m getting the following error when I attempt to use flask-mail to send an email through my gmail account.

error: [Errno 10061] No connection could

相关标签:
2条回答
  • 2020-12-08 23:01

    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)
    
    0 讨论(0)
  • 2020-12-08 23:24

    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

    0 讨论(0)
提交回复
热议问题