How to Send Mail From Internal Network to External Network Using Gmail | How to Configure Gmail SMTP Relay With Postfix #linuxtopic

Postfix configuration, postfix, How to Configure Gmail SMTP Relay With Postfix, postfix as smtp relay, configure postfix as smtp relay, postfix configure gmail as relay, configure postfix gmail smtp, send mail from gmail smtp server, linuxtopic, linux topic
Postfix configuration, postfix, How to Configure Gmail SMTP Relay With Postfix


Postfix configuration, postfix, How to Configure Gmail SMTP Relay With Postfix, postfix as smtp relay, configure postfix as smtp relay, postfix configure gmail as relay, configure postfix gmail smtp, send mail from gmail smtp server, linuxtopic, linux topic

In this topic we will send email from postfix to outside or external network using email relay, SMTP Relay is a protocol that allow to send email from localhost to external network.

Basic Information :

Gmail:
smtp.gmail.com

OS:
CentOS 7 - 64bit

Hostname:
lokesh.linuxtopic.com
192.168.156.100

Require Packages:
postfix
mailx

Configure Sendmail as Gmail SMTP Relay - Click Here..

Configure Postfix as Gmail SMTP Relay 

To Install packages:

yum install postfix  cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl mailx


Configure Postfix

Open configuration file of postfix  /etc/postfix/main.cf  and add below value

Backup current configuration 

cp -rv /etc/postfix/main.cf /etc/postfix/main.cf-`date -I`


Remove everything and add below lines in main.cf
vi /etc/postfix/main.cf

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/my-auth
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous



Configure Postfix SASL Credentials or Configure GMAIL as SMTP relay server

In this step we will add the Gmail credentials for authentication, To learn more about how to enable Click Here...

For authentication we will create a file like "/etc/postfix/my-auth" and add following line
vi /etc/postfix/my-auth
[smtp.gmail.com]:587 [email protected]:wwwxxxxyyyyzzzz

In the above we used gmail SMTP Server with 587 Port and email id which we want to send email from linux box with password, we do not use actual password here generate 16 character app password and use here. 


To  create postfix lookup table from the my-auth file and restrict access to everyone
postmap /etc/postfix/my-auth
chown root:postfix /etc/postfix/my-auth
chmod 640 /etc/postfix/my-auth

To allow SMTP service in firewall

firewall-cmd --permanent --add-service=smtp

Now we did all the required configuration and going to restart the postfix service, make sure sendmail service is disabled and stopped

To stop and disable if sendmail is running 

systemctl stop sendmail && systemctl disable sendmail

To start and enable postfix
 
systemctl enable postfix && systemctl restart postfix



To send test email

We can test postfix using mail command below

echo "This is postfix configuration using Gmail SMTP Relay by LinuxTopic" | mail -s "message" [email protected]

To verify from email



To verify from logs

tail -f /var/log/maillog




Thanks you !! 

I hope this topic gave you all the information you needed. If you have any further questions or would like more detailed directions feel free to contact us using any of the following sources.We look forward to talking to you.

No comments

Powered by Blogger.