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 "www.ubuntumail.net". 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 www.ubuntumail.net.
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/main.cf. 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/main.cf
The above command opens main.cf 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.net, ubuntumail, localhost.localdomain, localhost
#mynetworks = 127.0.0.0/8
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/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 ubuntumail.net. You will want to pay close attention to the mydestination line. As you can see that line contains:
ubuntumail.net, 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 = ubuntumail.net
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.
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.Advertisement
Ghacks is a technology news blog that was founded in 2005 by Martin Brinkmann. It has since then become one of the most popular tech news sites on the Internet with five authors and regular contributions from freelance writers.