Install Postfix for reliable email delivery - gHacks Tech News

Install Postfix for reliable email delivery

With your Ubuntu LAMP Server up and running (see my previous article "Installing Ubuntu Server 9.04" and "How to: install a LAMP server") and you are ready to set it up as a mail server. For the longest time Sendmail was the de facto standard Linux mail server. But over time serious security issues drove users to a much more reliable, secure, and easier to configure alternative. That alternative is Postfix. Postfix is much easier to configure than Sendmail and it is easier to add third-party "modules" (such as Spamassassin and ClamAV - will be discussed in later articles).

In this article you are going to learn how to install Postfix on your already running Ubuntu Server 9.04. I am going to assume you have it networked and have a domain registered that you want to use. At the end of this article you should have a working mail server, ready for use.

NOTE: For the purposes of this article, I will use the fake domain "". You will want to use your domain in place of that.

The first step is to install the software necessary. Since you already have LAMP up and running all you will need to do is install Postfix and it's dependencies. To do this open up a terminal and issue the following command:

sudo apt-get install postfix

The installation will not only install Postfix, but will start the Postfix daemon for you. You will most likely want to test this installation by running the old telnet test like so:

telnet localhost 25

You should see something like:
Connected to
Escape character is '^]'.
220 localhost.localdomain ESMTP Postfix (Ubuntu)

If you do, success! Now you are ready to take care of the configuration steps.


There is only one file you need to deal with in Postfix. That file is /etc/postfix/ There really isn't much to configuring this file (for a basic installation - which is all we are dealing with right now).

To set your Postfix installation up for your domain you will want to open that file for editing like so:

sudo nano /etc/postfix/

The above command opens in the Nano editor. What you need to look for is this section:

myhostname = ubuntumail
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination =, ubuntumail, localhost.localdomain, localhost
relayhost =
#mynetworks =
mynetworks = [::ffff:]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

As you can see, I have already configured the above section to work with our sample domain. You will need to go through the above section and insert your domain where you see You will want to pay close attention to the mydestination line. As you can see that line contains:, ubuntumail, localhost.localdomain

This helps to avoid mailloops in Postfix.

Some people also like to use the mydomain parameter, but since mydomain is taken from $myhostname by removing the first part (unless that would cause the domain to be a top-level domain) it can be redundant. If, however, your mail server serves your entire domain, you will need to use the mydomain parameter. For that you would insert:

mydomain =

at the top of the section shown above.

Once you have that configuration saved, restart Postfix with the command:

sudo /etc/init.d/postfix reload

To reload the mail server.


As this is a Linux box, you will want to make sure you have a user created for every email address you need to serve up. So create your users with your favorite user creation tool. Since you are most likely installing on a Ubuntu Server (sans GUI), you will be using the useradd command. You can accomplish this with the command:

sudo useradd -m USERNAME

Where USERNAME is the actual username you want to use. Next you will need to give the user a password with the command:

sudo passwd USERNAME

Where USERNAME is the actual username you want to use. You will be prompted to enter the password twice.

After you have entered the users, you can then test the mail server by sending an email from an external source to see if it arrives. If there is a problem make sure the first place you look is /var/log/mail.err.

Final thoughts

At this point you should have a basic, working mail server. Postfix does make this task much more simple than did Sendmail. In my next article I will cover adding Spamassassin to your Postfix mail server to keep SPAM from getting in.

  • We need your help

    Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

    We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats (video ads) or subscription fees.

    If you like our content, and would like to help, please consider making a contribution:


    1. Rupert said on October 25, 2009 at 12:45 pm

      Interesting little article. It’d be great if you could do an article on running your own smtp server. I use sendmail, but I still have to use yahoo smtp server. Is it possible to install and run your own smtp server so you aren’t relying on an external server to send mail, or is this not possible since otherwise spam would be even worse?

      1. Jack Wallen said on October 25, 2009 at 3:59 pm

        Postfix does serve as an smtp server. You would have to have your own domain (and a fixed IP address – if you are at home) – otherwise your outgoing email will get rejected left and right.

        1. Rupert said on October 25, 2009 at 5:53 pm

          Ahh, ok, cool, I shall go off and read the MAN pages. I guess it is not recommended to run your own SMTP server, in case of spam hacks and the like, but fun to play with none-the-less.

          Nice to see Ghacks carrying on the Linux stuff, it’s slowly becoming my bread and butter!

    2. Ganhar Dinheiro na Internet said on May 2, 2010 at 9:22 pm

      Thanks a lot again!

    Leave a Reply