HOLIDAY SALE! Save 50% on Membership with code HOLIDAY50. Save 15% on Mentorship with code HOLIDAY15.

13) Sending Emails & Email Verification Lesson

Set Up a Test Gmail Account

8 min to complete · By Brandon Gigous

In this lesson, you'll set up a secondary email account for your Python-Flask app. If you already have a Gmail account you want to use, you can skip the account part and only worry about the SMTP configuration. A secondary account is useful to just fart around with, and best of all, you don't have to risk your own security with your personal email.

One more thing: you don't have to use Gmail! This lesson covers how to set it up in Gmail, so instructions for setting up SMTP may vary for other email platforms.

Set Up a Gmail Account for your App

The first step is to make a new account that will be used to send and receive emails programmatically.

1. Create a Gmail Account

Head over to the Gmail Home Page and click "Create an account."

Screenshot of the Gmail Home Page

2. Enter Account Details

Then you'll be presented with a page where you'll enter your account information. The username/email you'll use must, of course, be unique across all of Google. To prevent you from spending too much time thinking of the perfect username (only to have it say it's taken) is to use a name like this:

flaskwebdev.<your name and/or initials here>

You can use any "First name" or "Last name" you want, as long as it's rated PG-13 or below. ;) Then the password. You probably know this, but make sure you write it down!

3. Configure Settings

Keep going through the steps to set up your account. Once you're done, you'll be presented with your new inbox. There should be a Settings gear on the top right corner of the screen. Click that.

Then once you're in Settings, click the "Accounts and Import" tab and click "Other Google Account settings."

Screenshot of the Accounts and Import, Other Account Settings

4. Turn Less Secure Apps ON

Once you get to the next page, click the "Security" tab.

Screenshot of the the Security Tab

With the Security tab open, scroll down to "Less secure app access", then click "Turn on access."

Screenshot turning 'less secure app access' being off

Then, turn "Allow less secure apps" to ON. This is required in order to send emails from your Flask App.

Screenshot turning 'less secure apps' on
Colorful illustration of a light bulb

Note: If you can't find this option for "less secure apps", you can continue to the next step.

5. Enable Two-Factor Authentication

Next, you'll need to enable two-factor authentication. This is required to enable app passwords, which is what you'll do next. Click "2-Step Verification" (which is the same thing as two-factor authentication).

Screenshot of the Signing in with 2-Step Verification

Then, you'll need to type in your phone number to use as a device to get your security codes to sign in with, in case it's needed. You can also choose a phone call, security key, or Google prompt. You may also be able to use Google Authenticator if you prefer that.

Colorful illustration of a light bulb

Note: The instructions for Google Authenticator are not provided here.

Screenshot of the Get Verification Code Options with 'text message' selected

Once you enter the code successfully after clicking "NEXT," go ahead and click the back button next to "2-Step Verification."

Screenshot of the the 2-step-verification menu

6. Create App Password

After setting up two-factor authentication, scroll back down to "Signing in to Google." Click "App passwords."

Screenshot of the 'Signing in to Google' menu

Then on the next page, where it says "Select device," click it and choose "Other (Custom name)." Then type in something like "flask-webdev" for the name.

Screenshot of the 'App Passwords' menu

Once you click "GENERATE," you'll be presented with a 16 character code. That's your new app password! Yes, your Flask app app password. And, yes, you'll want to write it down. ;) You will need this password in order to authenticate with Google's SMTP server and, therefore, be able to send emails.

Screenshot of the Generated App Password

Now You're Ready!

Summary: How to Set Up a Test Gmail Account for Less Secure Apps

Great, now all the account-creation stuff is done. You're ready to set up Flask-Mail to send email to your users and receive notifications about events that occur within your app. Here are the steps you took to create a secondary Gmail account:

  1. Visit Gmail and click create account
  2. Enter account details
  3. Go to setting
  4. Click Accounts and Import then other settings
  5. Turn less secure apps on
  6. Enable two-factor authentication

On to the next lesson!