One of the reasons why working at a startup excites me is the unpredictability of my future tasks. Case in point: I was recently asked to set up a mail server as a replacement for the Google Apps subscription currently in use. The requirements given to me specified that IMAP support and a web client are essential, as is the ability to send out emails not just to internal addresses, but also to other domains. After all, what good is a mail server if it can’t talk to the rest of the world? I decided to get started, but there was a tiny hold-up: I had no idea how to build a mail server!I’ve been using Ubuntu as my primary OS for over four years now, so I’m certainly not averse to using the terminal or SSH-ing into other computers, but I am no sys-admin and building a mail server was completely alien to me. Like most homework assignments and tasks, I started at Wikipedia. There are quite a few mail servers to choose from! I tried to set up Kolab, but I hit a few bugs and that attempt fizzled out. Then I discovered a brilliant tutorial to set up a mail server on Ubuntu 12.04 using Postfix + Dovecot, using MySQL as the database. The tutorial also includes setting up ClamAV [antivirus scanning for emails] and Spamassassin [spam filtering]. At first, Postfix and Dovecot seemed really intimidating, what with their myriad configuration files and options, but after several failed attempts at setting them up, I have a better understanding of the options and their use.
I followed that tutorial religiously up to the step when it dives off into setting up Horde. I tested that Dovecot is working well by keeping track of the /var/log/mail.log and /var/log/mail.err files [using tail -f] while following the instructions from this article
Horde, groupware that it is, provides calendar and other features that we don’t really need. I looked around for a different webmail package and came across Squirrelmail, but it’s UI is disappointing. The search for a web front-end ended with Roundcube. Its UI is simple and fresh.
Setting up Roundcube was a little tricky. I followed the instructions here, but the page is dated and missing some details.
- After executing the MySQL commands, don’t forget to “FLUSH PRIVILEGES;” before “exit”
- The latest version of Roundcube at the time of writing is 0.8.5, so be sure to update the archive download path. Use
- php date.timezone, seen in the screenshot as a warning, causes the installation to grind to a halt in version 0.8.5. As a workaround, edit your .htaccess file [ /var/www/.htaccess ] and specify a timezone as follows:
php_value date.timezone 'Asia/Kolkata'
Refer the PHP manual for all valid timezones
Once the installation was complete, I modified the default theme to include the company logo
To test the mail server using an email client, set up a few mailboxes using Postfixadmin, download an email client [I used Thunderbird]. During the “Add account” wizard, you may have to choose manual config and specify both IMAP and SMTP server paths as “mail.example.com” where example.com is your base domain. Usernames need to be specified fully – “email@example.com” instead of “testuser”
Why are mails from my mail server being classified as spam?
One of the first things I realised while trying to send and realise emails is that the emails being sent out by my mail server were being classified as spam by Gmail. There are several reasons for that. There’s a nifty service run by allaboutspam.com which checks your mail server for best practices. Send out an email to firstname.lastname@example.org from any mailbox on your mail server and you will receive a report email as an “undelivered email” after a little while. One of the quick fixes is to set up reverse DNS lookup for your domain. Once you’ve added appropriate DNS records for your domain, you can check the settings using the following commands in a terminal. Replace slashdot.org with your mail server domain [ mail.example.com ] and 184.108.40.206 with the IP address returned by the first command.
> host slashdot.org slashdot.org has address 220.127.116.11 > host 18.104.22.168 22.214.171.124.in-addr.arpa domain name pointer slashdot.org.
There were several failed attempts at setting up a mail server. I used VirtualBox VMs until I figured it out, and then set it up on an actual machine. I was originally asked to play around using Instacompute cloud instances, but unfortunately, the latest distro of Ubuntu that Instacompute chooses to support is Ubuntu 10.04, so I had to abandon the idea.
It was quite annoying having to download all the deb packages every time I screwed up and started over with a fresh VM, so I eventually realised I could just copy all the deb packages from /var/cache/apt/archives/ from one VM and use scp to copy them into future VMs.