📞 🇺🇸 +1 361 304 4309 📞 🇮🇳 +91 76769 02281 ✉️ [email protected]
Email Servers

How to Configure Postfix as Gmail SMTP Relay on Linux

How to Configure Postfix as Gmail SMTP Relay on Linux

Using Gmail as a relay for Postfix lets your server send emails reliably without worrying about IP reputation, blacklists or SPF configuration for outbound mail.

Prerequisites

Step 1 — Generate Gmail App Password

Google Account → Security → 2-Step Verification → App passwords → Generate new → copy the 16-character password

Step 2 — Install SASL Authentication

sudo apt install libsasl2-modules -y

Step 3 — Configure Postfix

sudo nano /etc/postfix/main.cf
# Gmail relay settings
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Step 4 — Create SASL Password File

sudo nano /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 [email protected]:YOUR_APP_PASSWORD
sudo postmap /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Step 5 — Reload Postfix

sudo systemctl reload postfix

Step 6 — Test

echo "Test relay email" | mail -s "Postfix Gmail Relay Test" [email protected]
sudo tail -f /var/log/mail.log

Look for status=sent in the logs.

Alternative — SendGrid Relay

# Use SendGrid for higher volume
relayhost = [smtp.sendgrid.net]:587
# sasl_passwd:
[smtp.sendgrid.net]:587 apikey:YOUR_SENDGRID_API_KEY

Conclusion

Gmail SMTP relay is ideal for low-volume server notifications. For high-volume transactional email, use SendGrid or our managed mail server service.

#postfix #gmail #smtp #relay #linux
Share this guide:
🛠️ Need Expert Help?

Don't want to do this yourself?

Our certified engineers implement this for you — correctly, securely, and within hours. Available 24/7 with 15-minute emergency response.

  • ✅ 19+ years experience
  • ✅ 60+ certified engineers
  • ✅ 1,600+ servers managed
  • ✅ 40+ countries served
  • ✅ Plans from $49/mo

Get Expert Help — Free Consultation

We respond within 4 hours · No commitment required

Please enter your name and a valid email.

No spam. Privacy Policy

Comments