Install Postfix on CentOS

Download Postfix

First lets start with updating the system

Yum update -y

Now we are going to install postfix

Yum install postfix cyrus-sasl-plain -y

If it is already installed, we can continue with the configuration of postfix

Now we have to set Postfix as our default MTA

alternatives --set mta /usr/sbin/sendmail.postfix

Configure Postfix

Now we are going to edit the configuration file of Postfix. Open this file with your favorite text editor In this case i will be using Nano If you want to use nano too, install it with:

yum install nano -y
nano /etc/postfix/

Paste the following at the bottom of the file:

mynetworks =, relayhost = []:587 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous smtp_tls_CApath = /etc/ssl/certs smtp_use_tls = yes

Replace with the SMTP server of your mail domain In this guide i will be using the SMTP server of GMAIL ( Let the brackets [ & ] stay in the relayhost.

Save and exit the file

Now we need to create the file with our username and password of our email account

nano /etc/postfix/sasl_passwd

Add the following to the new file

[]:587 youremailaddress:yourpassword

example: []:587

Save and exit the file

Change the permissions of the file with the following command

chmod 0600 /etc/postfix/sasl_passwd

Execute the following command to put the new changes into postfix

postmap /etc/postfix/sasl_passwd

Run the following command to check the configuration of postfix

postfix check

If you do not get any errors, then the configuration syntax is okay

Lets restart postfix to make it active with the new configuration

Service postfix restart

Install the mail command with the following command

yum install mailx -y

Test Postfix

Send yourself a test email with the following command

echo test | mail -s TEST

If you received the email, the postfix installation has succeeded.