qmail-pop3d worksheet

qmail is an entire MTA in its own right, but we will just be using its pop3 daemon because it supports Maildir format. It is lightweight and robust.


1. Compile and install

We will just build the parts of qmail we are interested in. A small patch enables some logging of POP3 accesses, otherwise no logging is done at all.

Starting in your home directory:

$ tar -xvzf /path/to/file/qmail-1.03.tar.gz
$ cd qmail-1.03
$ patch -p1 </path/to/file/qmail-log.patch
$ make qmail-pop3d
$ make qmail-popup
$ su
Password: <root password>
# cp qmail-pop3d qmail-popup /usr/local/libexec
# exit

$ cd ..
$ tar -xvzf /path/to/file/checkpassword-0.90.tar.gz
$ cd checkpassword-0.90
$ make
$ su
Password: <root password>
# cp checkpassword /usr/local/libexec
# exit

2. Edit /etc/inetd.conf

Put all of the following on one line in /etc/inetd.conf, changing pc1.t1.ws.afnog.org to your hostname

pop3  stream  tcp  nowait  root  /usr/local/libexec/qmail-popup qmail-popup
        pc1.t1.ws.afnog.org /usr/local/libexec/checkpassword
        /usr/local/libexec/qmail-pop3d Maildir

Send a HUP to inetd:

# killall -HUP inetd

Note that FreeBSD's inetd limits any particular services to being invoked no more than 256 times per minute. To raise this you use the -R flag, e.g. in /etc/rc.conf put:

inetd_flags="-wW -R 0"

This system is very modular. qmail-popup gets the USER and PASS from the remote client; in turn it runs checkpassword which checks the username/password are valid and sets the home directory; this in turn runs qmail-pop3d which executes POP3 commands.

This example uses checkpassword which looks up accounts in /etc/passwd, but qmail-pop3d can be used in virtual hosting environments simply by replacing checkpassword with an alternative program.


3. Test pop3 access

POP3 should now be functioning. Test it with a good username/password, and also a good username/bad password (to check that it is rejected).

$ telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK <2055.988915136@pc1.t1.ws.afnog.org>
user username
+OK
pass password
+OK
stat
+OK 12 17584
retr 1
+OK
... message
quit
+OK
Connection closed by foreign host.

If you applied the logging patch, you should also find log messages:

# tail /var/log/maillog
May  3 18:40:24 noc qmail-popup: POP3 login successful for brian from 127.0.0.1