Would you like to learn how to send an email using Python and Gmail? In this tutorial, we are going to show you how to use Python to send email notifications using the Gmail SMTP server.

• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Python 3.8.5

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Related tutorial - Python

On this page, we offer quick access to a list of tutorials related to Python.

Tutorial - Gmail Integration

First, we need to enable your Gmail account to receive connections from external programs.

Open your browser and access your Gmail account.

In our example, the following URL was entered in the Browser:

http://gmail.google.com

On the login screen, enter your Gmail username and password.

Gmail account

After the login, you need to access the following URL:

https://myaccount.google.com/signinoptions/two-step-verification

Enable the two step verification on this account.

After enabling the two step verification, you need to access the following URL:

https://security.google.com/settings/security/apppasswords

Create an application password.

Select the Gmail application and the type of device: Other.

gmail app password

In our example, we named the device POWERSHELL.

Click on the Generate button and take note of the randomly generated password.

Google generate app password

Next, you need to access the following URL:

https://accounts.google.com/DisplayUnlockCaptcha

Click on the Continue button to enable external access to your Google account.

gmail display unlock captcha

You have finished the required steps for the Gmail integration.

The Gmail integration will solve the following error.

Copy to Clipboard

You have finished the Gmail integration.

Tutorial Python - Send email using Gmail

Use Python to send an email using Gmail.

Copy to Clipboard

If the test was successful, you will receive the sent message.

Powershell - Send email Gmail

Use Python to send an email using Gmail containing an attachment.

Copy to Clipboard

Congratulations! You are able to use Python to send emails using Gmail.