Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com
huuphan.com. Powered by Blogger.

Configure Postfix to use Gmail as a Mail Relay

In this tutorial, I setup and Configure Postfix to use Gmail as a Mail Relay with 587 port.
  • OS: Centos
  • User: root
Install postfix
yum install postfix mailx cyrus-sasl cyrus-sasl-plain
To configure postfix to use Gmail as a Mail Relay
vi /etc/postfix/main.cf
Add or modify the following as below:
#To use smpt gmail with 587 port
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
smtp_tls_security_level = encrypt
# Location of CA certificates
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
To configure Gmail authentication
vi /etc/postfix/sasl_passwd
Add the line as below:
[smtp.gmail.com]:587    [email protected]:password
Running commands as below:
chmod 600 /etc/postfix/sasl_passwd
chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
postmap /etc/postfix/sasl_passwd
To restart postfix service
service postfix start
Test send a email 
echo "Test Mail" | mailx -v -r "[email protected]" -s "Test Mail 01" [email protected]

Troubleshooting - Enable "Less secure apps" access

The solve problem to link: https://support.google.com/accounts/answer/6010255?hl=en

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com