Configure postfix to relay mails using Gmail
Install postfix
1 2 |
apt update apt install postfix libsasl2-modules |
Create file
1 2 3 |
touch /etc/postfix/sasl_passwd chmod 600 /etc/postfix/sasl_passwd vi /etc/postfix/sasl_passwd |
Add
1 |
[smtp.gmail.com]:587 user@gmail.com:password |
Save and exit editor. Run
1 |
postmap /etc/postfix/sasl_passwd |
Edit postfix configuration file
1 |
vi /etc/postfix/main.cf |
Find and remove
1 |
relayhost = |
At end of the file, add
1 2 3 4 5 6 |
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
1 |
systemctl restart postfix |
Now all mails will be forwarded using gmail.
Test Email Delivery
Install mailutils
1 |
apt install mailutils |
On CentOS
1 |
yum install mailx |
To sent test email, run
1 |
echo "test" | mail -s "Testing gmail" you@yourdomain.com |
Check mail log
1 |
tail -f /var/log/mail.log |
See postfix