The following is a guide to setup a mail server using: postfix, dovecot, postgres, and roundcube on Ubuntu 12.04 Precise. I assume that you already have apache2 and postgres installed.
First let us install Postfix and Sasl by issuing the following command:
You will be asked some questions just leave everything as default, we will configure these packages in the next step. Run the following command to configure postfix:
Again, you will be asked some questions:
General type of mail configuration? Internet Site
System mail name? example.com
Root and postmaster mail recipient? Leave blank
Other destinations to accept mail for? example.com, localhost.example.com, localhost
Force synchronous updates on mail queue? No
Local networks? Leave default (127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128)
Mailbox size limit (bytes)? 0 (0 stands for unlimited)
Local address extension character? Leave default (+)
Internet protocols to use? ipv4 (most likely)
Next, let’s take care of certificates for TLS. You will be asked several questions during this process. Fill them in as you see fit.
1 2 3 4 5 6 7 8 9
Now we need to finish configuring Postfix for TLS and SASL. Run the following commands:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
Finally, we restart Postfix by issuing the following command:
Postfix Virtual Hosts
If you need to have multiple mail domains on this server follow these instructions. Otherwise skip to the SASL section.
First we need to tell postfix which domains we will use, to do that we create a file to list them in. To do this issue the following commands:
In file /etc/postfix/virtual/domains you will need to list all the domains that you wish to handle mail for, it might look something like this:
1 2 3
Now we need to setup the mappings between email addresses and local accounts by creating another file. To do this we issue the following command:
In file /etc/postfix/virtual/addresses you will need to list the mappings for each email address, it might look something like this:
1 2 3 4 5 6 7 8 9
The above examples setup four mappings:
Mail sent to firstname.lastname@example.org goes to the local user bob.
Mail sent to email@example.com goes to the local user steve.
Mail sent to @foo.com goes to the local user steve.
Mail sent to @mysite.com goes to the local user chris.
Now we need to tell postfix to use these settings by updating the /etc/postfix/main.cf file with the following:
We also need to create a hash of the /etc/postfix/virtual/addresses file. To do this we issue the following command:
Now to apply these changes we need to reload postfix, issue the following command:
Authentication will be done by saslauthd which will need to be configured to support a chrooted Postfix setup.
Fir we need to edit /etc/default/saslauthd and add or change the following settings so that they match:
Finish up SASL by creating the chroot directory, adding the postfix user to the sasl group, and then starting saslauthd. Run the following commands to do that:
1 2 3 4
Testing Postfix and SASL
At this point, core email services should be up and running. Let’s make sure that you’re in good shape before moving on. First, establish a connection with the mail server by running the following:
After establsihing a connection with the Postfix service, run:
You should see a few lines of output. Make sure that the two most important lines are there:
1 2 3 4
To exit telnet type
We now need to install and configure Dovecot, set the mailddir parameter, and restart the service to accept the change. To do that run the following commands:
1 2 3
If everything went smoothly you should now be in email nirvana. Each user has their own email account and you can move on to virtual accounts if you desire.
In this guide we will be installing Roundcube into directory /var/www/webmail.
First we need to find out what the latest version of Roundcube is. Go to the Roundcube dowload site, here, and notate the version number of the form x.x.x, as we will need this information later. Right click the download button and copy the link. At the time of writing this the version number was 0.8.5 and the download link was http://sourceforge.net/projects/roundcubemail/files/roundcubemail/0.8.5/roundcubemail-0.8.5.tar.gz/download.
Now that we have the link and version number we issue the following commands replacing xxx with the version number and http_link with the link we copied.
1 2 3
Now we need to fix file ownership for some of the newly created directories by issuing the following commands:
Now we need to create the database and database user for Roundcube in postgres. Issue the following commands to do that:
Now we’re all set to start the configuration of Roundcube to do that we will use the web based installer. Navigate to the following address in your web browswer:
From here just following onscreen prompts to configure your Roundcube instance.