Never Ending Security

It starts all here

Send-Only Postfix Server on LInux


Send-Only Postfix Server

Postfix is an MTA (Mail Transfer Agent), an application used to send and receive email. In this tutorial, we will install and configure Postfix so that it can be used to send emails by local applications only.

Why would you want to do that?

If you’re already using a third-party email provider for sending and receiving emails, you, of course, do not need to run your own mail server. However, if you manage a cloud server on which you have installed applications that need to send email notifications, running a local, send-only SMTP server is a good alternative to using a 3rd party email service provider or running a full-blown SMTP server.

Install Postfix

In this step, you’ll learn how to install Postfix. The most efficient way to install Postfix and other programs needed for testing email is to install the mailutils package by typing:

sudo apt-get install mailutils

Installing mailtuils will also cause Postfix to be installed, as well as a few other programs needed for Postfix to function. After typing that command, you will be presented with output that reads something like:

The following NEW packages will be installed:
guile-2.0-libs libgsasl7 libkyotocabinet16 libltdl7 liblzo2-2 libmailutils4 libmysqlclient18 libntlm0 libunistring0 mailutils mailutils-common mysql-common postfix ssl-cert

0 upgraded, 14 newly installed, 0 to remove and 3 not upgraded.
Need to get 5,481 kB of archives.
After this operation, 26.9 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Press ENTER to install them. Near the end of the installation process, you will be presented with a window that looks exactly like the one in the image below. The default option is Internet Site. That’s the recommended option for this tutorial, so press TAB, then ENTER.

Send-Only Postfix Server

After that, you’ll get another window just like the one in this next image. The System mail name should be the same as the name you assigned to your system. If it shows a subdomain like, change it to When you’re done, Press TAB, then ENTER.

Configure Postfix

In this step, you’ll read how to configure Postfix to process requests to send emails only from the server on which it is running, that is, from localhost. For that to happen, Postfix needs to be configured to listen only on the loopback interface, the virtual network interface that the server uses to communicate internally. To make the change, open the main Postfix configuration file using the nano editor.

sudo nano /etc/postfix/

With the file open, scroll down until you see the entries shown in this code block.

mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

Change the line that reads inet_interfaces = all to inet_interfaces = loopback-only. When you’re done, that same section of the file should now read:

mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only

In place of loopback-only you may also use localhost, so that the modified section may also read:

mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = localhost

When you’re done editing the file, save and close it (press CTRL+X, followed by pressing Y, then ENTER). After that, restart Postfix by typing:

sudo service postfix restart

Test SMTP Server

In this step, you’ll read how to test whether Postfix can send emails to any external email account. You’ll be using the mail command, which is part of the mailutils package that was installed in Step 1.

To send a test email, type:

echo "This is the body of the email" | mail -s "This is the subject line"

In performing your own test(s), you may use the body and subject line text as-is, or change them to your liking. However, in place of, use a valid email address, where the domain part can be,,, or any other email service provider that you use.

Now check the email address where you sent the test message.

You should see the message in your inbox. If not, check your spam folder.

Note: With this configuration, the address in the From field for the test emails you send will be, where root is your Linux username and the domain part is the server’s hostname. If you change your username, the From address will also change.

Forward System Mail

The last thing we want to set up is forwarding, so that you’ll get emails sent to root on the system at your personal, external email address.

To configure Postfix so that system-generated emails will be sent to your email address, you need to edit the/etc/aliases file.

sudo nano /etc/aliases

The full content of the file on a default installation of Ubuntu 14.04 is shown in this code block:

# See man 5 aliases for format
postmaster:    root

With that setting, system generated emails are sent to the root user. What you want to do is edit it so that those emails are rerouted to your email address. To accomplish that, edit the file so that it reads:

# See man 5 aliases for format
postmaster:    root

Replace with your personal email address. When done, save and close the file. For the change to take effect, run the following command:

sudo newaliases

You may now test that it works by sending an email to the root account using:

echo "This is the body of the email" | mail -s "This is the subject line" root

You should receive the email at your email address. If not, check your spam folder.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s