How to install and Configure Postfix Mail Server on CentOS 8
======
**Postfix** is a free and opensource **MTA** (Mail Transfer Agent) used for routing or delivering emails on a Linux system. In this guide, you will learn how to install and configure Postfix on CentOS 8.
* Hostname: server1.crazytechgeek.info (Ensure the domain name is pointed to the server’s IP)
### Step 1) Update the system
The first step is to ensure that the system packages are up to date. To do so, update the system as follows:
```
# dnf update
```
Before proceeding further, also ensure that no other **MTAs** such as **Sendmail** are existing as this will cause conflict with Postfix configuration. To remove Sendmail, for example, run the command:
```
# dnf remove sendmail
```
### Step 2) Set Hostname and update /etc/hosts file
Use below hostnamectl command to set the hostname on your system,
Additionally, you need to add the system’s hostname and IP entries in the /etc/hosts file
```
# vim /etc/hosts
192.168.1.13 server1.crazytechgeek.info
```
Save and exit the file.
### Step 3) Install Postfix Mail Server
After verifying that no other MTA is running on the system install Postfix by executing the command:
```
# dnf install postfix
```
[![Install-Postfix-Centos8][1]][3]
### Step 4) Start and enable Postfix Service
Upon successful installation of Postfix, start and enable Postfix service by running:
```
# systemctl start postfix
# systemctl enable postfix
```
To check Postfix status, run the following systemctl command
```
# systemctl status postfix
```
![Start-Postfix-check-status-centos8][1]
Great, we have verified that Postfix is up and running. Next, we are going to configure Postfix to send emails locally to our server.
### Step 5) Install mailx email client
Before configuring the Postfix server, we need to install mailx feature, To install mailx, run the command:
```
# dnf install mailx
```
![Install-Mailx-CentOS8][1]
### Step 6) Configure Postfix Mail Server
Postfix’s configuration file is located in **/etc/postfix/main.cf**. We need to make a few changes in the configuration file, so open it using your favorite text editor.
Postfix mail server mail logs are stored in the file “**/var/log/maillog**“, use below command to view the live logs,
```
# tail -f /var/log/maillog
```
![postfix-maillogs-centos8][1]
### Securing Postfix Mail Server
It is always recommended secure the communication of between clients and postfix server, this can be achieved using SSL certificates, these certificates can be either from trusted authority or Self Signed Certificates. In this tutorial we will generate Self Signed certificated for postfix using **openssl** command,
I am assuming openssl is already installed on your system, in case it is not installed then use following dnf command,
```
# dnf install openssl -y
```
Generate Private key and CSR (Certificate Signing Request) using beneath openssl command,
**Note:** If Your IP is not blacklisted anywhere then your email to external domain will be delivered otherwise it will be bounced saying that IP is blacklisted in so and so spamhaus database.
### Check Postfix mail queue
Use mailq command to list mails which are in queue.
```
# mailq
Mail queue is empty
#
```
And that’s it! Our Postfix configuration is working! That’s all for now. We hope you found this tutorial insightful and that you can comfortably set up your local Postfix server.