Configure postfix to relay mails using Gmail

Install postfix

apt update
apt install postfix libsasl2-modules

Create file

touch /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
vi /etc/postfix/sasl_passwd

Add

[smtp.gmail.com]:587    [email protected]:password

Save and exit editor. Run

postmap /etc/postfix/sasl_passwd

Edit postfix configuration file

vi /etc/postfix/main.cf

Find and remove

relayhost = 

At end of the file, add

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Restart postfix

systemctl restart postfix

Now all mails will be forwarded using gmail.

Test Email Delivery

Install mailutils

apt install mailutils

On CentOS

yum install mailx

To sent test email, run

echo "test" | mail -s "Testing gmail" [email protected]

Check mail log

tail -f /var/log/mail.log

See postfix

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *