07 Nov 2014

Email setup

It's important to practise what you preach, so starting a new service we wanted to build our infrastructure in-line with our ethos and apply the latest technology to deliver quality results.

E-mail hosting is seen as something of a dark art and most people stay away from it, opting instead for a solution which someone else looks after. Much of this reputation comes from postfix, a mail delivery system first released in 1998 with its architecture of small parts - which pass an email message around to get the job done. This can be confusing to get right and getting it wrong can open the server up for abuse, which in turn brings tough penalties from the various spam protection services.

Although managed email hosting is great for a small company, our need for multiple SMTP accounts (system emails for example) would soon cost us a fair amount, as usual email providers charge per account.

Our ideal set up is quite simple - just straight forward email sending and an IMAP inbox (which stores the mail on the server and lets us synchronise with it from various devices). For a robust service, we would like to have backup and a way to rapidly restore the service if the machine hosting it has an issue.

Having used various deployment mechanisms before, we have selected a combination of Ansible and Docker. Docker containers provide a way to build and deploy an isolated package with predictable results - which lets us develop and test the software locally and be sure that it will work exactly the same once deployed. Ansible in our experience makes deploying infrastructure to remote machines a breeze with its direct approach, expressive configuration and instant feedback.

Our first port of call was to look around the open source community for a docker script that provides an email service, which was surprisingly fruitless - most people just stay away from hosting own email. We have found one script which provided part of the puzzle: https://github.com/lava/dockermail . There were a few issues though:

  • It came bundled with web-mail clients, calendar and other unwanted extras
  • The configuration was built into the container, which means adding a new email account would require rebuilding and re-deploying the whole thing.

So having taken the mail server core of this project, we have rebuilt it to allow easy configuration changes and have released it back into the open source: https://github.com/adaline/dockermail .

Our Ansible set-up builds the docker image, deploys it with the necessary configuration, configures the firewall, makes sure the service comes back when the server is rebooted and configures backup - all in 70 lines of code!

We are very happy with our new email - it's rapid, robust and headache free.

All blog posts