Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Using a Google App Password to Send Emails in Development with Flask

blog/cards/using-google-app-passwords-to-send-emails-in-development-with-flask.jpg

As of May 30th 2022 Google disabled the less secure apps option to login to Gmail over SMTP, 2FA + app passwords fill that void.

Quick Jump: Demo Video

For a long time I had less secure apps enabled on a secondary throw away Gmail account. That option let you login to your account directly with your email address and password. I set that up 7 or 8 years ago before Google required phone numbers to create an account. I only used this account to test emails in development with a real email provider.

As of May 30th 2022 Google no longer supports the less secure apps option and it’s described in more detail in their support pages https://support.google.com/accounts/answer/6010255.

In my Build a SAAS App with Flask course we send emails and I suggested using Gmail in development to really test sending emails. I just updated the course to go over what we’re going to cover in the video below which is enabling 2FA on a Google account (a requirement for app passwords), creating an app password and then using it in a Flask app.

Technically you could use this method for any web app (Rails, Django, etc.). We’re just logging in over SMTP and instead of using your Google password directly it will be the app’s password.

The video below goes into all of the details. I also recorded this video in a “live” style where I’m doing all of these things for the first time without any practice runs to reflect what it’s really like to solve every day problems as a software developer.

Demo Video

Timestamps

  • 0:17 – Less secure apps were convenient before 2FA and app passwords
  • 1:00 – We’ll cover enabling 2FA, creating an app password and then using it
  • 2:15 – Enabling 2FA using a Google Voice number and text message
  • 7:09 – Creating an application password
  • 12:22 – Using the app password in the Flask app and seeing if I can send an email
  • 14:09 – Troubleshooting why the email wasn’t sent
  • 15:46 – Checking if it works again and it does
  • 16:28 – Checking when an app password was last used and revoking it

How do you send emails in development? Let us know below!

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per month (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments