Written by Rahul, Updated on February 18, 2019
Mail Servers, Postfix email server, mail, mailserver, Postfix, smtp
Postfix is fast and popular SMTP server widely used. The main job of postfix is to relay mail locally or to the intended destination outside the network. Some of the most popular SMTP servers are Sendmail, Postfix, and Qmail. By default, Sendmail comes pre-installed with CentOS/RHEL 5. We will need to remove it and install Postfix.
You may also like:
Step 1 — Install Postfix
If Postfix not already installed on your machine, Install it using the following command. Also, remove sendmail if already installed.
yum remove sendmail
yum install postfix
Make postfix as default MTA for your system using the following command
alternatives --set mta /usr/sbin/postfix
If above command not work and you get the output as “/usr/sbin/postfix has not been configured as an alternative for mta“. Use below command to do the same else skip it
alternatives --set mta /usr/sbin/sendmail.postfix
Step 2 — Configure Postfix
Let’s start postfix configuration. Edit Postfix configuration file /etc/postfix/main.cf in your favorite editor and make following changes.
myhostname = mail.tecadmin.net
mydomain = tecadmin.net
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost, $mydomain
mynetworks = 127.0.0.0/8, /32
relay_domains = $mydestination
home_mailbox = Maildir/
After executing above command edit the postfix configuration file and make sure all changes are done properly.
Step 3 — Restart Postfix Service
As we have done basic Postfix configuration, So restart Postfix service to read changes of configuration. Also, configure to autostart on system boot.
service postfix restart
chkconfig postfix on
Step 4 — Open Firewall Port
Now if your system is configured to use iptables firewall, So add firewall rules to make postfix accessible from outside, using following commands.
firewall-cmd --permanent --add-port=25/tcp
firewall-cmd --permanent --add-port=25/udp
Step 4 — Open Firewall Port
Now if your system is configured to use iptables firewall, So add firewall rules to make postfix accessible from outside, using following commands.
firewall-cmd --permanent --add-port=25/tcp
firewall-cmd --permanent --add-port=25/udp
Step 5— Test send an email
Use sendmail command to send a test email.
sendmail recipient@elsewhere.com
From: you@example.com
Subject: Test mail
This is a test email
.