Connection refused when sending mail with Flask-Mail Connection refused when sending mail with Flask-Mail flask flask

Connection refused when sending mail with Flask-Mail


  1. You must set up flask config:

    app = Flask(__name__)app.config.from_object(__name__)mail = Mail(app)
  2. Use 465 port.


MAIL_USE_TLS = True then use 587 portMAIL_USE_SSL = True then use 465 port


I also have the same issue and I was also using Flask-Mail. It was actually part of Flask-User package. I have also enabled TLS port, since my mail server was using TLS and I disable SSL. I also change the port 465 to 587. The code of my application is follows:

 MAIL_PORT =           int(os.getenv('MAIL_PORT',            '587')) MAIL_USE_SSL =        int(os.getenv('MAIL_USE_SSL',         False)) MAIL_USE_TLS =        int(os.getenv('MAIL_USE_TLS',         True))

This change solved my problem.