How to Install Postfix on CentOS/RHEL

Postfix is free open source mail transfer agent. The primary job of postfix is to pass on email locally or to intended location outside the system. Some of the most well-known SMTP web servers are Sendmail, Postfix and Qmail. By standard Sendmail comes pre-installed with CentOS/RHEL 5. We will need to remove it and set up Postfix.

yum remove sendmail
yum install postfix

Use following command to make postfix as default MTA for your system:

alternatives --set mta /usr/sbin/postfix

If you get 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

Now we are going to configure the postfix , Edit Postfix configuration file /etc/postfix/main.cf  and make following changes:

myhostname = mail.cpanelplesk.com
mydomain = cpanelplesk.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost, $mydomain
mynetworks = 127.0.0.0/8, /32
relay_domains = $mydestination
home_mailbox = Maildir/

Restart Postfix service to read the changes of settings. Also set up to automatic start on system boot.

service postfix restart 
chkconfig postfix on

Now add firewall rules to make postfix accessible from outside, using following commands: 

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT 
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 25 -j ACCEPT

Congratulation , now you have postfix installed and you are all set to send email.