You are here:

Easy Setup Postfix on CentOS

Download Postfix

First, update the system

Yum update -y

Next, we’ll install Postfix

Yum install postfix cyrus-sasl-plain -y

If Postfix is already installed, proceed with its configuration.

Now, set Postfix as the default MTA.

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

Configure Postfix

Now, let’s edit the Postfix configuration file using your preferred text editor. I’ll be using Nano in this case. If you don’t have Nano installed, you can do so with:

yum install nano -y
nano /etc/postfix/main.cf

Paste the following at the bottom of the file:

      mynetworks = 127.0.0.0/8, 10.11.1.0/24 relayhost = 

      [mail.example.com]: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 ‘mail.example.com’ with the SMTP server of your mail domain. In this guide, I will be using the SMTP server of Gmail, which is ‘smtp.gmail.com’. Ensure the brackets [ & ] stay in the relayhost.

Save and exit the file

Create a file with your email account’s username and password

nano /etc/postfix/sasl_passwd

Add the following to the new file

     [smtp.hmail.com]:587 youremailaddress:yourpassword

example: [smtp.gmail.com]:587 test@gmail.com:password123

Save and exit the file

Modify the file permissions using the following command

chmod 0600 /etc/postfix/sasl_passwd

Execute the following command to apply the new changes to Postfix

postmap /etc/postfix/sasl_passwd

Check Postfix configuration with the command

postfix check

If no errors are reported, the configuration syntax is correct.
Now, restart Postfix to activate the new configuration

Service postfix restart

Install the mail command using the following command

yum install mailx -y

Test Postfix

Send a test email to yourself using the following command

echo test | mail -s TEST youremailaddress@yourdomain.com

If you received the email, the Postfix installation was successful.

Was this article helpful?
Dislike 0