Postfix is a popular open source Mail Transfer Agent (MTA) which is used in order to route and deliver an email on a Linux system. Approximately 25% of public mail servers on the Internet use Postfix.
In this tutorial we will teach you how to get up and running fairly fast with Postfix on an Ubuntu 14.04 server.
To be able to follow this guide, you will need to have a Fully Qualified Domain Name pointed directly at the Ubuntu 14.04 server.
Installing the Software
The process to install Postfix on Ubuntu 14.04 is fairly simple as the software is in Ubuntu’s default package repositories.
Seeing as this is your first operation using apt in this session, you should update to the local package index and before installing the Postfix package.
sudo apt-get update sudo apt-get install postfix
You will have to type in the type of mail configuration which you would like to have for your server. In our example, we will be selecting ‘Internet Site’ since the description is the best match for our server.
Now, you should be asked for the Fully Qualified Domain Name (FQDN) of your server. The full domain name should look like this (like domain.com). Technically, a FQDN has to end with a dot, although Postfix does not need it. You could just enter it like the below.
Next, the software is going to be configured with the settings you have provided. That should take care of the installation, though we need to configure other items that were not prompted for when you were installing.
You may need to change some basic settings in the main Postfix configuration file.
Start by opening up the file using root privileges with the text editor.
sudo nano /etc/postfix/main.cf
Now, find the ‘myhostname’ parameter. In the configuration, the FQDN we have chosen was added to the ‘mydestination’ parameter, though ‘myhostname’ stayed set as localhost. You have to point this to your FQDN as well.
Myhostname = domain.com
If you want to configure mail so it is forwarded to other domains or desire to deliver to addresses which do not map 1-to-1 with system accounts then you may remove the ‘alias_maps’ parameter and switch it with ‘virtual_alias_maps’.
Then you would have to change the location of the hash to \/etc/postfix/virtual’.
virtual_alias_maps = hash:/etc/postfix/virtual
The parameter ‘mydestination’ has been edited using the FQDN you have entered during the installation. This parameter should hold any domain that this installation of Postfix is going to be responsible for.
This is configured for the FQDN as well as the localhost.
As mentioned above, the ‘mydestination’ parameter has been edited with the FQDN which you entered during installation. It is the parameter which holds any domains that this Installation of Postfix will have to be responsible for.
An important parameter to mention is the ‘mynetworks’ parameter. That will define the computers which are able to use the mail server. This will have to be set to local only (127.0.0.0/8 like the other representations).
Editing this will allow other hosts to use it and that can be a big vulnerability which could lead to extreme cases of spam.
The line needs to be set like below; it is meant to be set automatically but you can double check the value in your file.
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
Configuring Additional Email Addresses
You can configure more email addresses by making aliases. These aliases can be used to deliver mail to other user accounts on the system. If you would like to use this functionality, be sure you have configured the ‘virtual_alias_maps’ directive as shown above.
You are going to use this file in order to configure your address mappings. Make the file by entering: ‘sudo nano /etc/postfix/virtual’
In the file, you may choose emails which you wish to create on the left-hand side, then the username to deliver the mail to on the right-hand side. It will look like the below.
In your installation, you will be creating a couple of email addresses and afterwards routing them to some user accounts. You can also set up certain addresses to forward to a couple accounts by simply entering a comma seperated list like showing in the following.
firstname.lastname@example.org email@example.com firstname.lastname@example.org email@example.com testuser,root
Now, if you are finished, save and close the file. Next, you may implement your mapping by entering this command: ‘sudo postmap /etc/postfix/virtual’.
Lastly, reload the service to read your changes: ‘sudo service postfix restart’.
Test your Configuration
Now feel free to test that your server can receive and route mail correctly by sending mail from your normal email address to one of your user accounts on the server or any of the aliases you may have set up.
After you have sent an email to:
Then you will receive a mail delivered to a file which matches the delivery username in ‘/var/mail’.
As an example, you can read this message by looking at this file.
This should contain all of the email messages, including the headers, in one big file. If you would like to consume your email in a more friendly way then you may need to install a few helper programs.
sudo apt-get install mailutils
That should give you access to the mail program which you can use to check your inbox.
This will grant you an interface to interact with your mail.
Now you should have basic email functionality configured on your server.
Do not forget about the importance of securing your server and making sure that Postfix was not configured as an open relay. Mail servers are usually targeted heavily by attackers as this would allow them to send out massive amounts of spam email; make sure you have set up a firewall and have implemented various security measurements to protect your server.