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


Install Package 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

Mail Successfully Received.
If mail is not in the inbox, check SPAM folder.

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

By mithun

One thought on “Easy Steps to Configure mail on Linux”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.