Configure Postfix as Send-Only SMTP Server on Fedora 29

|
Last Updated:
|
|

In this guide, we are going to learn how to install and configure Postfix as send-only SMTP server on Fedora 29. Postfix is a free and opensource mail transfer agent (MTA) that routes and delivers emails to the systems that are external to it. In this article, we are going to learn how configure Postfix to act a as send-only SMTP server such that it can only send emails rather than receive nor process them.

Configuring Postfix as Send-Only SMTP Server on Fedora 29

Install Postfix on Fedora 29

Postfix is available on Fedora default repos. Before you can install it, ensure that you system packages are up-to-date.

dnf update
dnf install postfix

Once the installation is done, proceed to configure Postfix as send-only SMTP server.

Start and enable Postfix to run on system boot

systemctl start postfix
systemctl enable postfix

Configure Postfix as send-only SMTP server

In order for Postfix to process and send mails from the server in which it is running, i.e the localhost, we need to configure it to listen on the loopback interface, 127.0.0.1 only. Therefore, open the main configuration file for Postfix, /etc/postfix/main.cf, for editing and replace the value of inet_interfaces to localhost or loopback-only if it is not set by default. The inet_interfaces is set to localhost by default on Fedora 29. If this is not the case for you, make appropriate adjustments.

vim  /etc/postfix/main.cf

...
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost

# Enable IPv4, and IPv6 if supported
inet_protocols = all
...

If you make any changes, be sure to restart Postfix for the changes to take effect.

Before you restart, be sure to check if any errors;

postfix check

If all good, restart

systemctl restart postfix

Test the Postfix SMTP server

To confirm that your local Postfix can actually send mails, you can try to send a test mail. Replace the [email protected] with your external email ID.

mail -s "Testing Send-only Postfix SMTP" [email protected] < /dev/null

You should be able to receive an empty mail with subject “Testing Send-only Postfix SMTP” on your email account.

If you encounter an error, bash: mail: command not found, run the command below to install mail command.

dnf install mailx

Forward System Mails

In order to receive system mails (mails sent to root user) on an external mail account, you need to configure system mail forwarding. By default, system-generated mails are forwarded to root user on the local system as defined by the following line on /etc/aliases configuration file.

# Basic system aliases -- these MUST be present.
mailer-daemon:  postmaster
postmaster:     root

To forward all mails sent to root user, you need to forward them to your external email address. Therefore, open the aliases configuration file and make the changes as shown below;

vim /etc/aliases
# Basic system aliases -- these MUST be present.
mailer-daemon:  postmaster
postmaster:     root
root:   [email protected]

Be sure to replace [email protected] with your email ID.

In order to rebuild the database for the mail aliases file, /etc/aliases, run the command newaliases every time this file is changed in order for the changes to take effect.

newaliases

Verify Mail Forwarding

Now that the configurations are done, you can test to verify that your send-only SMTP server can send mails. You can use the mail command to do the test as shown below;

echo "Testing Mail Forwarding to Postfix SMTP" | mail -s "Forward System Mails" root

Similarly, you should be able to receive the mail on your external email account.

You can also check our previous article on How to Install and Setup iRedMail Mail Server on Ubuntu 18.04 LTS.

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
koromicha
I am the Co-founder of Kifarunix.com, Linux and the whole FOSS enthusiast, Linux System Admin and a Blue Teamer who loves to share technological tips and hacks with others as a way of sharing knowledge as: "In vain have you acquired knowledge if you have not imparted it to others".

2 thoughts on “Configure Postfix as Send-Only SMTP Server on Fedora 29”

Leave a Comment