Follow through this tutorial to learn how to configure Postfix to use Gmail App Passwords. Previously, Gmail would allow you to use “third-party apps or devices which ask you to sign in to your Google Account using only your username and password“. For example, if you were configuring Postfix to use Gmail SMTP relay, then you may need to turn on Less Secure App Access so that the username/password authentication may work. However, this flexibility come to an end as from May 30, 2022.
Configure Postfix to Use Gmail App Passwords
So, how can you configure Postfix to use Gmail SMTP relay after less secure app access is disabled? Google, as a result of disabling less secure app access, recommends the use of more secure apps with your account.
Therefore, as an alternative to the use of less secure apps with Postfix Gmail SMPT relay configuration, you can configure Postfix to use Gmail App Passwords (Please also note that Gmail do not recommend the use of App password, “App Passwords aren’t recommended and are unnecessary in most cases. To help keep your account secure, use “Sign in with Google” to connect apps to your Google Account“).
So, how can you configure Postfix to use Gmail App Passwords as an alternative to the use of former less secure apps access method?
1. Login to your Google Account
Login to your Gmail account that you want to use with Postfix for relay.
2. Enable 2-Step Verification
If not already enabled, navigate to Security section > Signing in to Google and enable 2-Step verification for your account.
- Click on 2-Step Verification > Get Started.
- You will be prompted to enter your account password to confirm that the account is actually yours, -:).
- Continue to add your phone number and click SEND to get the verification code.
- Enter the code that you receive on your phone number to confirm that 2-Step verification works.
- Once done, click TURN ON to enable 2-Step Verification on your account.
3. Create App Passwords
- Next, go back to Security section > Signing in to Google. Just below the 2-Step Verification option is App Passwords setting.
- Click App Passwords to create and use app passwords.
- If prompted, enter your account password. You will then proceed to App Passwords settings page.
- Select your specific app from the available list. If using Postfix, then you can select Other (Custom name)
- Enter the name of the App, e.g Posfix and click GENERATE to create App password.
- Copy the 16-character password and click DONE.
- This is the password that you will use for your account on Postfix.
4. Install Gmail Account App Password on Postfix
Next, edit the Postfix SMTP SASL credentials and replace the password with the 16-character password created above.
[smtp.gmail.com]:587 [email protected]:ixxxxxxxxxxxxxxd
[email protected] and
Save and exit the file.
Regenerate SASL password DB file.
5. Restart Postfix Service
Once that is done, run Postfix configuration check;
If there is any error, then the command will print it to standard output. Otherwise it exits with no output and exit status of 0.
Then restart it;
systemctl restart postfix
6. Test Postfix Email Relay via Gmail SMTP
You can now test if all is okay as follows;
echo "Test Postfix Gmail SMTP Relay" | mail -s "Postfix Gmail SMTP Relay" [email protected]
You can tail the logs to check the delivery status;
... Aug 27 22:42:10 debian11 postfix/pickup: 2EAFD653BB: uid=0 from=<[email protected]> Aug 27 22:42:10 debian11 postfix/cleanup: 2EAFD653BB: message-id=<[email protected]> Aug 27 22:42:10 debian11 postfix/qmgr: 2EAFD653BB: from=<[email protected]>, size=371, nrcpt=1 (queue active) Aug 27 22:42:12 debian11 postfix/smtp: 2EAFD653BB: to=<[email protected]>, relay=smtp.gmail.com[220.127.116.11]:587, delay=2.8, delays=0.02/0.02/2/0.78, dsn=2.0.0, status=sent (250 2.0.0 OK 1661629332 14-20020a170906308e00b0073bdb2f6f28sm2340234ejv.217 - gsmtp) Aug 27 22:42:12 debian11 postfix/qmgr: 2EAFD653BB: removed ...
And that is how you can configure Postfix to use Gmail App Passwords instead of the now deprecated less secure app access option.
That brings us to our guide on how to configure Postfix to use Gmail App Passwords.
Configure Postfix to Use Gmail SMTP on CentOS 8
Configure Postfix to Use Gmail SMTP on Ubuntu 18.04
Configure Postfix as Send-Only SMTP Server on Fedora 29