We will be sending e-mail with Gmail. So the first thing we need to do is setup Google security.
On May 30th, 2022 Gmail removed the setting to allow "less secure" applications to access an account with just username and password.
What this means is that you have to enable some other means of account security.
One way to do it is to use API Authentication with OAuth2 which Google documents here.
Another way, which I will describe here, is to turn on two-factor authentication.
In order to allow our Python client script to access Gmail accounts we will enable two-factor authentication (2FA) which Google calls " 2-step verification".
With 2FA you add an extra layer of security to your account in case your password is stolen. After you set it up, you’ll sign in to your account in two steps using:
- something you know, like your password and
- something you have, like your phone.
To enable 2FA:
- Open your Google Account.
- In the navigation panel, select Security.
- Under “Signing in to Google,” select 2-Step Verification
Click the blue GET STARTED button:
Login using your password. Make sure you are using the right account.
Enter your phone number and click SEND:
Wait for the confirmation code to arrive and enter it in:
Click the TURN ON button:
2FA should now be enabled:
Now we will generate a special password that our app can use as the 2-step verification.
Back in the Signing in to Google panel select "App passwords" to add a new password:
Under the "Select app" drop-down select " Other":
Give your app a name and click GENERATE:
Write down (copy to clipboard) your generated password to use in the app:
We should now have our generated app password:
Note:
Use App password instead of your account password.