Configure Postfix on RedHat Linux system to send mail
Hi Friends,
In this post, we will set up Postfix on the Redhat server for sending emails.
What is Postfix?
Postfix is a free, open-source mail transfer agent (MTA) used for routing and delivering emails. The utility uses the Simple Mail Transfer Protocol (SMTP) to transfer emails between servers.
Setting up Postfix on Red Hat Linux to send email is a common and essential task for many server administrators. Postfix is a popular mail transfer agent (MTA) that can be configured to handle outgoing email.
1. Install Postfix
We can use ‘yum’ package manager to install postfix on our Redhat system.
sudo yum install postfix
2. Configure Postfix
The main configuration file for Postfix is `/etc/postfix/main.cf`. We will edit this file using vi editor.
sudo vi /etc/postfix/main.cf
Add or update the following lines:
# Set your hostname (FQDN)
myhostname = your-server-hostname.example.com
# Specify the relay host (your ISP's SMTP server)
relayhost = [smtp.your-isp.com]:587
# Enable SASL authentication (if required)
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:YOUR-SMTP-USER-NAME-HERE:YOUR-SMTP-SERVER-PASSWORD-HERE
smtp_sasl_security_options = noanonymous
# TLS/SSL Configuration (if your ISP requires it)
smtp_tls_security_level = may
smtp_tls_note_starttls_offer = yes
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
inet_interfaces = 127.0.0.1
When done, close and exit the editor using :wq
sudo vi /etc/postfix/sasl_passwd
4. Start Postfix
Enable and start the Postfix service:
sudo systemctl enable postfix
sudo systemctl start postfix
We can verify if email is sent or not using log file:
sudo tail -f /var/log/mail.log
If you get mail cmd not found error then you may need to install mailx. After installing it, you can retry and check.
We can use the `mail` command to test sending an email:
echo "This is a test email" | mail -s "Test Email" recipient@example.com
If you get mail cmd not found error then you may need to install mailx. After installing it, you can retry and check.
sudo yum install mailx
That’s it! We have successfully set up Postfix on our Redhat system to send email through a relay server. We might need to consider additional security mesaures when we use it in production environment.