qmail/MySQL - troubleshooting

Oh dear. You followed the instructions above to the letter but it still didn't do what you were expecting. Now, assuming you were expecting it to do the right thing, that suggests a problem. Here's what you do.

First of all re-read the configuration instructions at least once. Make sure you've paid particular attention to the directory permissions and you haven't made any silly typos in the database. If it helps, set up the selfsame users I mention in the examples! If you're still stuck, follow these steps:

In the patched qmail source tree there's a utility called addrexp. It uses the exact same algorithm that qmail-send does to determine where to deliver a message. If it isn't built, type make addrexp to get it and then copy it into a directory in your PATH. Assuming babasse.com is listed in control/me and the user dmp is set up as above, you should see the following. Note that I'm directly inserting shell commands into my editor...

brotteaux:/usr/src/new/qmail-1.03$ ./addrexp diane.p@tterson.net
dmp@babasse.com
brotteaux:/usr/src/new/qmail-1.03$ echo $?
1

Remember that the hostname after the @ should match control/me. addrexp returns 0 if the address is local, 1 if the address is a local virtual domain and 2 if it is remote. So that's why I checked its return value.

Now we can discard the @whatever and concentrate on the user.

brotteaux:/usr/src/new/qmail-1.03$ qmail-getpw dmp | xargs -0 echo
dmp 800 100 /home/mail/dmp   

Check that the fourth column (the home directory) has the correct permissions (see above) and that its owner and group IDs are as listed in the second and third columns. Most problems are caused by that not being the case...

Finally we simulate actual delivery of the message with qmail-local.

brotteaux:/usr/src/new/qmail-1.03$ qmail-local -n dmp /home/mail/dmp dmp "" "" babasse.com test ./Maildir/
maildir ./Maildir/
did 1+0+0

If the output of qmail-getpw contained a dash and an extension at the end (eg: iain-legacy) you would replace the two sets of double quotes with the dash and extension (ie two arguments "-" and "ext"). See the manpage for qmail-local.

Tracing queries

If you suspect the database isn't behaving, turn on logging by editing the Makefile and look at the queries qmail is running. Try those queries at the MySQL prompt and see if you get back the expected results.

Try also setting MySQL itself to debug all queries sent to it. Make sure that what qmail says is happening, is actually happenign.

Tracing process execution

A very effective way of debugging qmail (with or without these patches) is to use strace (Linux) or truss (Solaris/BSD) to follow the qmail programs as they do their work. Look at which directories and files qmail is attempting to access. Make sure those directories and files have the right permissions set. Try using su or setuidgid to simulate the behaviour of the qmail users yourself.