Watch the configuration steps on Yout tube Click Here
My Environment Details
Oracle Linux Server release 7.4
Putty -> For accessing the Linux Server
Relay host Details ->(Credentials)
Access to the Internet
Pre-Requsite On GMAIL (Enabling Two-Factor Authentication (2FA))
Login to GMAIL Account
Generate an App Password for Postfix
Enable Two-Factor Authentication
Enable Two-Factor Authentication on GMAIL
Linux Postfix mail configuration – Pre-requsite
- Putty -> For accessing the Linux Operating system
- Access to the Internet
- Postfix package installed
- Telnet package to check and troubleshoot Smtp port access
- Relay host Details ->(Credentials, username & password)
- [smtp.gmail.com]:587
- [smtp.office365.com]:587
- Postfix Relay Server
- backup of the postfix configuration file by executing command
- cp /etc/postfix/main.cf /etc/postfix/mainbkp.cf
Yum install postfix
Check reachability of the server by telnetting, also make sure
telnet smtp.gmail.com 587
telnet smtp.office365.com 587
Configure the Postfix Relay Server (Gmail)
Postifx configuration file vi /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
inet_protocols = ipv4
Configure the Postfix Relay Server (Office365)
relayhost = [smtp. office365.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
inet_protocols = ipv4
Steps for Username & Password configuration
Usernames and passwords are stored in sasl_passwd file in the /etc/postfix/ directory. We have mentioned this file path already on postfix configuration file
“ smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd”
Format : [smtp..com]:587 emailid:password
Gmail
[root@oggaci12c postfix]# vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 oracleprohowto@gmail.com:fXXXzXdpXXXtpqys
Create hash db file for Postfix
The credential file sasl_passwd created for that we need to create a hash db file.
postmap /etc/postfix/sasl_passwd
The above command will create a hash db file on postfix folder
Send test Mail & Confirm
echo “mail is working”| mail -r oracleprohowto@gmail.com -s “linux it’s ok” oracleprohowto@gmail.com
Troubleshooting
Execute mailqcommand to see whether the mail has gone from the Linux server or in queue. It will point out the error. Here we will list out some common issues faced
Issue I – Wrong credentials
Usernames and passwords is wrong in sasl_passwd file stored in the /etc/postfix/ directory.
Format : [smtp..com]:587 emailid:password
vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 oracleprohowto@gmail.com:iXXXzXdpXXXtpqys
Re-create hash db file once necessary changes are made to password file
and execute postmap /etc/postfix/sasl_passwd
Issue II – refused to talk to me: 421 Cannot connect to SMTP server
If you are on an office network, the issue could be due to the firewall. Talk to your network admin and request to allow the mail traffic from the Linux server. If you are testing the mail sending on a VM on a laptop, you can test mail after connecting the laptop wifi to a mobile hotspot.
Clean the mail queue
To clean the mail queue of all failed transaction execute command
postsuper -d ALL
Thanks mithun! What a fantastic time saving concise and clear set of steps. Was very helpful.