Configure Flask-Mail to use GMail Configure Flask-Mail to use GMail flask flask

Configure Flask-Mail to use GMail


  1. The server is "smtp.gmail.com".
  2. The port must match the type of security used.
    • If using STARTTLS with MAIL_USE_TLS = True, then use MAIL_PORT = 587.
    • If using SSL/TLS directly with MAIL_USE_SSL = True, then use MAIL_PORT = 465.
    • Enable either STARTTLS or SSL/TLS, not both.
  3. Depending on your Google account's security settings, you may need to generate and use an app password rather than the account password. This may also require enabling 2-step verification. You should probably set this up anyway.
MAIL_SERVER = 'smtp.gmail.com'MAIL_PORT = 465MAIL_USE_SSL = TrueMAIL_USERNAME = 'username@gmail.com'MAIL_PASSWORD = 'app password generated in step 3'


A small but important addition to davidism's answer:

You must have '2-step verification' enabled on your Google account before you're able to set up app-specific passwords.