Configure Postfix to Use Gmail App Passwords

Last Updated:

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, Postfix can be configured 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“).

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.

configure Postfix to use Gmail App Passwords
  • 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

configure Postfix to use Gmail App Passwords
  • 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.
configure Postfix to use Gmail App Passwords
  • Copy the 16-character password and click DONE.
configure Postfix to use Gmail App Passwords
  • 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.

vim /etc/postfix/sasl_passwd
[]:587 [email protected]:ixxxxxxxxxxxxxxd

Replace the userid@gmail and password accordingly.

Save and exit the file.

Regenerate SASL password DB file.

postmap /etc/postfix/sasl_passwd

5. Restart Postfix Service

Once that is done, run Postfix configuration check;

postfix 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;

tail /var/log/mail.log

Sample output;

Aug 27 22:42:10 debian11 postfix/pickup[14560]: 2EAFD653BB: uid=0 from=<[email protected]>
Aug 27 22:42:10 debian11 postfix/cleanup[14579]: 2EAFD653BB: message-id=<[email protected]>
Aug 27 22:42:10 debian11 postfix/qmgr[14561]: 2EAFD653BB: from=<[email protected]>, size=371, nrcpt=1 (queue active)
Aug 27 22:42:12 debian11 postfix/smtp[14581]: 2EAFD653BB: to=<[email protected]>,[]: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[14561]: 2EAFD653BB: removed

And that is how you can Postfix can be configured to use Gmail App Passwords instead of the now deprecated less secure app access option.

Other Tutorials

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

Configure Postfix to Use Gmail SMTP on Ubuntu 20.04


We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
I am the Co-founder of, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

Leave a Comment