Wanna see this logo while booting your 2.6 kernel? Click here!

01.02.2005 22:09

Exim 3.36 with MySQL Support in Debian

Today I configured my first exim MTA [EN] with MySQL [EN] Support. Debian does not provide MySQL-Support in its exim package, so you have to recompile exim from source to enable MySQL Support.

First of all you need some additional packages installed to avoid compile problems, here's a listing of these packages:
Of course you also need exim and mysql-server installed. I used exim 3.36 and mysql-server-4.1.

To compile the exim-source, you first have to download it.
apt-get source exim
This command creates a subdirectory called exim-$version in your CWD. You now have to edit the file exim-$version/debian/editme-diff as shown below:


 # LOOKUP_INCLUDE=-I /usr/local/ldap/include -I /usr/local/mysql/include -I /usr/local/pgsql/include
-# LOOKUP_LIBS=-L/usr/local/lib -lldap -llber -lmysqlclient -lpq            
+LOOKUP_LIBS=-lldap -llber

-# LOOKUP_INCLUDE=-I /usr/local/ldap/include -I /usr/local/mysql/include -I /usr/local/pgsql/include
+LOOKUP_INCLUDE=-I /usr/local/ldap/include -I /usr/include/mysql -I /usr/local/pgsql/include
-# LOOKUP_LIBS=-L/usr/local/lib -lldap -llber -lmysqlclient -lpq
+LOOKUP_LIBS=-lldap -llber -lmysqlclient
cd to the exim-$version directory and issue the following command to build the package:
dpkg-buildpackage -uc -b
If this process succeeds, you'll get the compiled debian package outside the exim-$version directory. For those of you, who don't want to compile exim-mysql, you can use my precompiled package for Debian Sarge [DEB].

Finally install the package with the following command, and your exim-mysql should be up and running (check that with ps}.
dpkg -i exim_3.36-13_i386.deb
Now you have to prepare your MySQL Database and modify exim.conf. This part of my "howto" derives from this site [EN], but has some modifications for using the standard mailfile format instead of maildir, etc. Can't help myself, I don't like maildir...
create database maildb;
grant select,insert,update,delete on maildb.* to mail@localhost identified by 'secret';
flush privileges;

use maildb;
    id                    char(12 8) DEFAULT '' NOT NULL,
    crypt                 char(12 8) DEFAULT '' NOT NULL,
    clear                 char(12 8) DEFAULT '' NOT NULL,
    name                  char(12 8) DEFAULT '' NOT NULL,
    uid                   int(10) unsigned DEFAULT '8' NOT NULL,
    gid                   int(10) unsigned DEFAULT '8' NOT NULL,
    home                  char(255) DEFAULT '' NOT NULL,
    mailfile              char(255) DEFAULT '' NOT NULL,
    quota                 char(255) DEFAULT '' NOT NULL,
    KEY id (id(128))

CREATE TABLE domains (
   domain char(12 8) NOT NULL default '',
   KEY domain (domain)

INSERT INTO domains (domain) VALUES ("example.com");
'secret' means the password that will be stored in the MySQL users-table.
The default entry for uid and gid is 8, which is the UID/GID of the system account "mail" on Debian systems.
"example.com" has to be replaced by your domain, of course.

To set up a test-user, issue the following command within the mysql shell:
INSERT INTO users (id, crypt, clear, name, home, mailfile) VALUES (
  "luser@example.com", ENCRYPT("test"), "test", "My name is Luser",
  "/nonexistent", "/data/mail/luser");
Verify, that the direcory /data/mail (or the directory you want to hold your mailfiles) exists and is owned by root.mail, mode 2775. If you want your users to have a homedirectory, replace "/nonexistent" with the new $HOME of this user.

At last, we have to configure exim by editing exim.conf. Here's my exim.conf - feel free to pick out everything you need or make a diff with your default exim.conf to see what has been changed.

To test exim, send yourself an email (either by using the mail/mailx utility or by speaking SMTP to localhost:25). Monitor /var/log/exim/mainlog while doing so and afterwards check /data/mail/$username if the mail has arrived.