Gmail flash: connection refused

I get the following error when I try to use a flash drive to send email through my gmail account.

error: [Errno 10061] The connection could not be completed because the target machine actively refused it

I tried to configure flask mail in various ways, but so far I always get this error.

Here are some sample configurations I tried:

  • app = Flask(__name__) mail = Mail(app) app.config.update(dict( DEBUG = True, MAIL_SERVER = 'smtp.gmail.com', MAIL_PORT = 465, MAIL_USE_TLS = False, MAIL_USE_SSL = True, MAIL_USERNAME = 'my_username@gmail.com', MAIL_PASSWORD = 'my_password', )) 
  •  app = Flask(__name__) mail = Mail(app) 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', )) 
  • This configuration is from a mega-jar tutorial ( http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xi-email-support )

     app = Flask(__name__) mail = Mail(app) app.config.update(dict( DEBUG = True, # email server MAIL_SERVER = 'smtp.googlemail.com', MAIL_PORT = 465, MAIL_USE_TLS = False, MAIL_USE_SSL = True, MAIL_USERNAME = 'my_username', MAIL_PASSWORD = 'my_password', # administrator list ADMINS = ['my_username@gmail.com'] )) 

Has anyone else encountered a similar problem?

+8
python flask flask mail
source share
2 answers

As far as I can tell, there is nothing wrong with this configuration. The only problem is that your application does not use it. Before initializing Mail you must update the configuration:

 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) 
+18
source share

In addition to requesting zero323, adding a configuration before creating the Mail object should help, but if it gives an SMTPAuthentication error with the gmail server, then for testing purposes only, you can let less secure applications log in for a while - https://myaccount.google.com/ security # signin

+1
source share

All Articles