How to Configure a Postfix Relay through Gmail on Linux(Centos/RHEL/OEL) 7
Postfix is a robust mail server that is available on most Linux versions. In this post, I will share steps to configure Postfix as a relay through Gmail SMTP.
Steps:
1. Install the required packages like postfix, mailx, cyrus-sasl-plain.
yum -y install postfix cyrus-sasl-plain mailx
2. Restart Postfix services
systemctl restart postfix
3. Enable Postfix to automatically start as server boot.
systemctl enable postfix
4. Configure Postfix
The main configuration file for postfix is /etc/postfix/main.cf
Add below entries in the file postfix config file.
#####This can be your host name####
myhostname = oel7.lab
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
5. Configure Postfix SASL(Security Layer) Credentials
This would be the gmail credentials of the account which would be used as SMTP.
vi /etc/postfix/sasl_passwd
Add following line:
[smtp.gmail.com]:587 username:dummypass
The username password should be actual password.
Save the file and close.
6. Postfix lookup table has to be generated from the sasl_passwd file.
Run below command
postmap /etc/postfix/sasl_passwd
7. Restrict permission on the sasl_passwd files
chown root:postfix /etc/postfix/sasl_passwd*
chmod 640 /etc/postfix/sasl_passwd*
8. Reload the Postfix configuration
systemctl reload postfix
9. Test the relay by sending mail
echo "Hello" | mail -s "test" mymaiil@domain.com
Note:
The Postfix configuration must be reloaded after updating the main.cf file.
systemctl reload postfix
Post a Comment
Post a Comment