IT Consulting in Richmond, BC, Canada
Minek Systems Inc. - IT Consulting Vancouver, Canada, Linux Consulting
email fax 305-356-7141
250-2639 Viking Way, Richmond, BC, V6V 1N3, Canada

Exim - Dovecot Integration | SMTP - IMAP

There is many SMTP and IMAP servers on the market; either Open Source or proprietary. One of the most popular SMTP servers used to be sendmail, unfortunately it does not work with MAILDIRS, it only support MAILBOXES.
In my opinion the idea that each email recipient must have UNIX system account (MAILBOX) is insane. The only 'right' way of setting up a mail server, is to utilize so called virtual accounts. We should entirely forget about system user accounts, and only focus on virtual accounts (with MAILDIR support).
Also, MAILBOXES require to store all emails in one big text file, which makes it slow for pretty much anybody these days...

Now, what choices we have ? There is qmail, courier, exim and others.
Since in most cases I recommend running Debian based Linux distros (e.g. Ubuntu), the SMTP server of my choice is exim4, which comes by default with Debian and Ubuntu, and it's very fast and reliable.
That's it for SMTP (MTA).

What about users reading their mail ? POP3 is so out of date, and has so many limitations, so we all should just forget about it.
I think most of us as familiar with most od web based email such as Hotmail or Yahoo Mail, or corporate products such as MS Exchange / MS Outlook.
That's why it make sense to consider IMAP server integrated with SMTP server. SMTP server receives/sends emails, IMAP server/client provides users with good interface and features to organize and store emails effectively.

From my experience, one of the best IMAP servers around, is Dovecot

Since Debian/Ubuntu packages are not really up to date with Dovecot, and also do not provide automated way of integrating it with exim server, it is necessarry to integrate them manually.

Here is how:
We are assuming that exim4 (standard Debian package) is already installed, configured and working in standard, non-IMAP way.
As for Dovecot:
First - download and compile latest version of Dovecot. At the moment of writing this (Feb 2009), that latest version is 1.1.11. Building Dovecot is easy, usually I use standard configure script with two options:

./configure --prefix=/usr/local/dovecot --without-pop3d
make install

You will need to create new user accounts (and groups):


I decided to store all email in the following format: /opt/maildir/DOMAIN/USER
E.g. for email address all emails will be stored in:
Appropriate directories must be created by hand, and owned by imap:imap.
Here is an example of the structure and ownership; please note how aliases to accounts/domains are done.

Now, we need to configure Dovecot.
Here is an example Dovecot config file: /usr/local/dovecot/etc/dovecot.conf. Please have a look.
Next step - edit file /usr/local/dovecot/accounts.txt where IMAP usernames and passwords will be kept.
Every time new email account needs to be added, a new entry in this file needs to be created, and appropriate directories in /opt/maildir need to be added.

As you can see, I decided to use full email addresses as usernames, and I keep passwords as plain text (for a sake making this guide as easy as possible).

Dovecot should be up and running, you can test IMAP connections with Mozilla Thunderbird (login with full email address as a username and apropriate password, as defined in accounts.txt).

Now it's time to force exim to deliver emails to /opt/maildir/...... directory rather to system account's mail boxes.
We need to add two files (one transport and one router) to exim's configuration:

Once this is done, modify
file, so it looks like this (last line modified to use dovecot transport):
# /etc/exim4/update-exim4.conf.conf



After all these changes, execute
dpkg-reconfigure exim4-config
restart exim4, and all should work just fine.

This configuration works very fast and can handle enourmous load, even on lousy server. It is definitely faster and more pleasant to use than outsourced IMAP service or GMail (Google Apps configured for your own domain).

As an addition, we should add some kind of SPAM and virus filters or SMTP proxy, but this is subject for a separate guide.

If you don't spend most of your work time checking and answering emails, outsourced IMAP service or GMail might be OK. Google Apps are getting more and more popular these days, as they require only DNS changes to have your email system running, but if are dealing with higher volume or emails, it can be really frustrating sometimes (speed and login timeouts) if accessing GMail via IMAP client.
We have been dealing with all of these solutions in the last few years of our IT consulting assignments, setting up servers like this is a routine task, and can be done in just few hours.

SMS Gateway 

Our Last Five Customers

  • WCB, Richmond

Technical Guides

Other Links