Linux

How to Install and Configure Postfix as a Send-Only SMTP Server

posfix-as-an-smtp-server

Postfix is an open-source mail server started at IBM in 1998, it helps to route traffic between various mail servers across the internet. It is still being used because postfix strives to be fast, uncomplicated to use, and trustworthy. To run a mail-in Linux we need to understand the separate roles that servers can have in an email configuration. The role that is most important with regards to emails is what we call a null client. Please refer to the following guides for information: How to locate directory file context and restore it with SELinux, and other related guides such as how to create and deliver a report based on system utilization on a Linux-based OS and how to install Static pods in Kubernetes and how to use container insights to get the full benefits of Azure Monitor for Azure Kubernetes workload. 

A null client is a mail server that is running in SMTP process

SMTP is a simple mail transfer protocol. Every Linux server runs SMTP processes and they run to send mail to the outside.

Null clients are usually configured with a forwarder and a mail forwarder is a server that sits somewhere else, which can send out emails to the rest of the world. concisely, we will call the Null client an SMTP server.

Also, there is an email role where emails can be received for users, which is a server that is known as an IMAP/POP server. It listens for all incoming messages on port 25. Null Clients do not receive messages from the outside world, null clients are just for sending messages out to the internet.

Installation on RHEL

#dnf install postfix 
postfix-installed-1

It has been installed so let’s start it

#Postfix start
postfix-start

On Centos

Postfix comes out of the box with a null client configuration installed on Centos and started automatically; this is because you need postfix for processes that need to send out information on the internet. So, the next thing to do would be to the check the status using the command below. we shall be using centos for the configuration.

#systemctl status postfix
status-postfix-1

Configuration of a Null Client

the configuration file for postfix can be found at

#cd /etc/postfix
#ls

The config file that we need to edit is the main .cf file

main.cf_
main.cf

when we are in the /etc/postfix directory. Run ls to see all the files and chose main.cf, the next step would be to edit the main.cf file. The file has a lot of parameters, and we can change them to suit what we want the postfix mail server to do.

vim main.cf

One of such parameters that we can change is inet_interfaces. In the config file, inet _interfaces are set to localhost, and this means that the postfix sever won’t accept any incoming messages. So, we need to fix that by replacing the local host with the IP address device.

inet
Inet interfaces

Let’s verify that the default configuration does not allow messages from the outside into the server with the command

#netstat -tulpen
netstattulpen
netstat -tulpen

We see that the inode is bound to the local host and not accessible from the outside

Another parameter in the main.cf is the relayhost. If we want our postfix server to relay messages (forward messages) to another host, we need to change it there.

relayhost
relay host

So, we just need to add the name or IP address of the forward or relay host. It is widespread practice to put the IP address or name in square brackets as shown above so that the postfix server will not do a DNS/MX mail lookup as it will just send the messages directly to the relay host. Before we put any IP address, we must make sure that the owner has given their consent because by default nobody would want to be used as a reply host and become a” dumping ground” for unwanted messages. To make sure that the change take place we must run the command below so that the change is persistent.

# systemctl restart postfix

The following commands can be used to start, stop, and restart the mail system. Please remember that the following commands are only available to the superuser, which implies you must be root to use them.

 Important Commands

Objective: Stop Postfix

To stop postfix use:

# Postfix stop

Objective: Start Postfix

To start postfix use:

#Postfix start

Objective: Restart Postfix

To reload postfix use:

#Postfix restart

Objective: Reload postfix

To reload the config files use:

#postfix reload

Objective: Postfix status

To check the status of postfix:

#Systemctl status postfix

Distro specific Start stop commands

Debian Centos/RHEL/Fedora
$ sudo service postfix start
$ sudo service postfix stop
$ sudo service postfix restart
# /sbin/service postfix start
# /sbin/service postfix stop
# /sbin/service postfix restart

Summary

Postfix is an open-source mail server with its config fil called main.cf located at /etc/postfix. To be able to forward messages we need to change the configuration of the relay host in the config file with the IP address or name of the relay host that we want to send the messages to.

Subscribe
Notify of
guest
1 Comment
Inline Feedbacks
View all comments
m101p
5 days ago

Very nice

1
0
Would love your thoughts, please comment.x
()
x
Kindly subscribe to TechDirectArchive
This is default text for notification bar