Serverspace Black Friday
JH
Joe Harris
February 27, 2021
Updated June 7, 2023

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

CentOS Linux SMTP

Using another OS?

Select the desired version or distribution.

Configuring a mail server to send messages only can be very useful when administering servers. For example, to receive notifications from Cron or monitoring systems. In this tutorial we will look at how to install and configure Postfix as a send-only SMTP server on CentOS 8. First, you need to have a domain name from which mail will be sent, as well as authorize on the server as root.

Installing and configuring Postfix

Let's install the required packages. Postfix is the mail server itself, and mailx is the environment for handling email.

dnf install -y postfix mailx

Activate the start together with the system and run Postfix.

systemctl enable --now postfix

Open the Postfix configuration file.

nano /etc/postfix/main.cf

You need to find the inet_interfaces parameter and assign it the localhost value if it is different at the moment. In my case, the parameter was listed several times, but with the correct value.

inet_interfaces = localhost

Set the myhostname parameter to your domain name.

myhostname = domain-name.com

Uncomment this line:

myorigin = $myhostname

Make the line look like this and replace the domain name with your own:

mydestination = $myhostname, domain-name.com, localhost.$mydomain, localhost

Save and close the file and restart the system.

reboot

Now you need to configure the hostname for the server.

hostname domain-name.com
echo "domain-name.com" > /etc/hostname

These settings are sufficient in many cases, but some mail servers have fairly strict spam filters and will reject mail. In this case, additional steps are required. One of which is setting up a PTR record for a domain. Usually, to do it, you need to contact the support service of the company that provided you with a public IP address.

Postfix testing

To send a test message, use the command:

echo "Mail delivery test" | mail -s "[Server] New e-mail" mail@domain.com

The mail address must be replaced with a real one, and the text in quotation marks represents the body of the letter and its header.

Configuring mail forwarding

Sometimes you need to receive the host's internal mail to an external mailbox. For example, to receive system notifications. There are aliases for these purposes. Let's take a look at setting up mail forwarding for root. Open the file with aliases.

nano /etc/aliases

To add mail forwarding for root to an external mailbox, add a line with your mailbox:

root: mail@domain.com

Save the file and enter the command to apply the changes:

newaliases

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
33145 North Miami, FL 2520 Coral Way apt 2-135
+1 302 425-97-76
700 300
ITGLOBAL.COM CORP
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.