IT Consulting in Richmond, BC, Canada
Minek Systems Inc. - IT Consulting Vancouver, Canada, Linux Consulting
email info@minek.com 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
make install

You will need to create new user accounts (and groups):
/etc/passwd:
imap:x:1006:1006::/tmp:/bin/false
dovecot:x:1007:1007::/tmp:/bin/false

/etc/group:
imap:x:1006:
dovecot:x:1007:

I decided to store all email in the following format: /opt/maildir/DOMAIN/USER
E.g. for email address test@myserver.com all emails will be stored in:
/opt/maildir/myserver.com/test
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:
/etc/exim4/conf.d/transport/99_dovecot
/etc/exim4/conf.d/router/01_exim4_dovecot

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

dc_eximconfig_configtype='internet'
dc_local_domains='myserver.com:otherserver.com'
dc_other_hostnames='myserver.com:otherserver.com'

dc_local_interfaces='123.123.123.123'
dc_readhost=''
dc_relay_domains=''
dc_minimaldns='false'
dc_relay_nets='127.0.0.1'
dc_smarthost=''
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname=''
dc_mailname_in_oh='true'
dc_localdelivery='dovecot_transport'

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

  • www.belgian-telecom.be
  • www.Semotus.com
  • WCB, Richmond
  • www.AustinHamilton.ca
  • www.icore.net

Technical Guides

Other Links