Install Postfix on CentOS

Problem

Install Postfix if it is not currently installed on your system.

tl;dr

Run these commands (CentOS/RHEL):

yum install postfix -y
service postfix start
chkconfig postfix on

Solution

By default, most Linux installations come with Postfix already installed. This is not enough to run a full email server, however it is more than sufficient to send an occasional message from the command line, or a script. It is also quite useful if you wish to configure email alerts, such as multiple failed login attempts, or low disk space on the server.

Mail can be sent from command line via the mail user@example.com command. But what if you encounter the error below?

[root@kitty ~]# mail user@example.com
Subject: Low Disk Space
Disk space on this server is low.
-Support
EOT
/usr/sbin/sendmail: No such file or directory
"/root/dead.letter" 11/345
. . . message not sent.

The /usr/sbin/sendmail: No such file or directory message shows that you do not have Postfix (or another mail client) installed. To install Postfix, begin with:

yum install postfix -y

This will install the mailer service in its most basic configuration. Any emails sent will usually have the format user@1.2.3.4 where user is the system user account currently being used (such as root or vlad), and 1.2.3.4 is the server's external IP address.

Configure FQDN

If your IP address has an FQDN (Fully Qualified Domain Name, such as esecuredata.com), you can configure it in Postfix settings so mail is received from user@domain.com instead. To do so, open the /etc/postfix/main.cf configuration file:

nano /etc/postfix/main.cf

Change the following line:

#myhostname = host.domain.tld

To

myhostname = example.com

Where example.com is your registered fully-qualified domain name assigned to this server.

Start Postfix and Configure Autostart

Make sure to start Postfix so you can send mail:

service postfix start

Also configure it to automatically start at boot:

chkconfig postfix on


Was this article helpful?

mood_bad Dislike 0
mood Like 2
visibility Views: 8685