In this guide, we want to teach you to Install and Configure Postfix Mail Server on Centos 7.
Email is one of the fastest and most reliable communication mediums for businesses and individuals. The software which runs this whole communication medium is called mail server and mail client. The mail server that is also known as Mail Transfer Agent is responsible for transferring email from server to server on the internet, while the mail client performs the activities of retrieving these emails.
Postfix can run on UNIX-based systems including AIX, BSD, HP-UX, Linux, macOS X, and Solaris and this makes it a go-to choice as most of the world’s systems already run on UNIX-based OS. Postfix is also available as a default mail transfer agent software by many operating system vendors and supports SMTP. Each vendor has its own customization to the original software as per its requirements.
Postfix offers an amazing set of powerful features like junk mail control, database support, log management, and many more. It has wide support for databases like MySQL, Memcache SQLite, PostgreSQL, and LDAP.
You can visit this guide on Introducing 5 Linux Mail Servers, to get more information about the best mail server for centos.
Steps To Install and Configure Postfix Mail Server on Centos 7
To install Postfix on your server, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide the Initial Server Setup with Centos 7.
Now follow the steps below to complete this guide.
Install Postfix on Centos 7
First, you need to update your local package index with the following command:
sudo yum update -y
Then, run the command below to check whether Sendmail is installed or not:
rpm -qa | grep sendmail
If you didn’t get any output that means you don’t have Sendmail installed and you can keep going.
If you have Sendmail installed on your server, you need to remove it with the following command:
sudo yum remove sendmail*
At this point, you can check whether you have Postfix installed on your server or not:
rpm -qa | grep postfix
Next, if you don’t have it installed on your server, use the command below to install Postfix on Centos 7:
sudo yum install postfix
Configure Postfix on Centos 7
At this point, you need to make some configuration changes to the Postfix main configuration file.
First, open the file with your favorite text editor, here we use vi:
sudo vi /etc/postfix/main.cf
At the file, uncomment the myhostname line and set it to your hostname:
myhostname = your-hostname
Uncomment and set the domain name at the line below:
mydomain = your-domain-name
Also, uncomment the line below:
myorigin = $mydomain
Uncomment and Set ipv4 at the following line:
inet_interfaces = all
Set the line below to all:
inet_protocols = all
Comment on the following line:
#mydestination = $myhostname, localhost.$mydomain, localhost,
Uncomment and add the IP range at the following line:
mynetworks = 192.168.1.0/24, 127.0.0.0/8
Finally, uncomment the line below:
home_mailbox = Maildir/
When you are done, save and close the file.
At this point, you need to start and enable your Postfix Mail service on Centos 7 with the following commands:
# sudo systemctl enable postfix # sudo systemctl restart postfix
Verify that your Postfix service is active and running on Centos 7:
sudo systemctl status postfix
Output postfix.service - Postfix Mail Transport Agent Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2022-06-18 04:34:50 EDT; 5s ago Process: 22248 ExecStop=/usr/sbin/postfix stop (code=exited, status=0/SUCCESS) Process: 22265 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS) Process: 22261 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS) Process: 22258 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS) Main PID: 22338 (master) CGroup: /system.slice/postfix.service ├─22338 /usr/libexec/postfix/master -w ├─22339 pickup -l -t unix -u └─22340 qmgr -l -t unix -u
How To Test Postfix Mail Server
At this point, you need to create a new user for testing. To do this, run the command below:
sudo useradd postfixtester
Add a password for your user:
sudo passwd postfixtester
When you are done, you will get the following output:
Output passwd: all authentication tokens updated successfully.
After adding the user let’s check the server access using telnet. If you don’t have telnet installed on your server, use the command below to install telnet on Centos 7:
sudo yum install telnet
Then, run the following command:
telnet localhost smtp
Once you have successfully done the configuration you will get the following output:
Output Trying ::1… Connected to localhost. Escape character is '^]'. 220 your-hostname ESMTP Postfix
Start your transaction by writing the below command:
250-hostname 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN
Once you get 250 DSN you can send mail.
Finally! You have postfix installed and emails getting sent! You are all set to use your server as your private SMTP server to send emails.
For more information, you can visit the Postfix Documentation page.
at this point, you learn to Install and Configure Postfix Mail Server on Centos 7.
Hope you enjoy it.
You may be interested in these articles too: