title: flask-mail gmail: connection refused
body: <p>I'm getting the following error when I attempt to use flask-mail to send an email through my gmail account.</p>
  
  <blockquote>
    <p>error: [Errno 10061] No connection could be made because the target machine actively refused it</p>
  </blockquote>
  
  <p>I've tried configuring flask-mail in various ways, but so far I always get this error.</p>
  
  <p>Here are some sample configurations I've tried:</p>
  
  <ol>
  <li>
  
  <pre><code>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',
  ))
  </code></pre></li>
  <li>
  
  <pre><code>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',
  ))
  </code></pre></li>
  <li><p>This configuration is from the flask mega-tutorial (<a href="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xi-email-support">http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xi-email-support</a>)</p>
  
  <pre><code>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']
  ))
  </code></pre></li>
  </ol>
  
  <p>Has anyone else experienced a similar problem?</p>