qmail HOWTO - Configuration of the Services
Posted by admin on October 25 2007 10:34:44

!!!WARNING!!!

This HOWTO (which should be named "misleading install guide that is too old to be taken seriously) no longer matches Oli's at pofo.de. Please direct your attention to lifewithqmail.org for better help and more details. (I'm only leaving this up until I can figure out how to gracefully remove it.)
SF - 2005-11-30

Contents:
2.1 Qmail
2.2 vpopmail
2.3 courier-imap
2.4 qmail-conf
2.5 daemontools

This section deals with the configuration of the services installed in Chapter 1.

2.1 qmail

Firstly, the start scripts from the FreeBSD port must be deactivated.

rm /usr/local/etc/rc.d/qmail.sh

With the next three commands, we will create three empty files. If qmail were not installed with vpopmail, these three files would indicate the account to which emails to the respective (special) accounts would be forwarded.

touch /var/qmail/alias/.qmail-postmaster \
  /var/qmail/alias/.qmail-root \
  /var/qmail/alias/.qmail-mailer-daemon

Due to the fact that vpopmail is now responsible for the domains and subsequent users, the qmail POP3 daemon must be configured so that it is no longer responsible for any domains.

echo "" > /var/qmail/control/locals

The next three commands/lines cause the server to respond to others with a valid domain name (in conformation with the proper RFC's). This also allows for emails to be processed where the domain is not directly indicated [(i.e. the email coming from the account "steve" will be tagged with @domain1.tld).]

hostname > /var/qmail/control/me
hostname | sed "s/`hostname -s`.//g" > /var/qmail/control/defaultdomain
hostname | sed "s/`hostname -s`.//g" > /var/qmail/control/plusdomain
2.2 vpopmail

After a successful authentication through one of the mail services, SMTP will be available for relay to that specific IP for a given amount of time. Thusly, unauthorized relaying will be prohibited or impossible. In order to make the the time period limited, the following should be placed in your crontab file:

crontab -l >crontab
echo "40 * * * * /usr/local/vpopmail/bin/clearopensmtp >/dev/null 2>&1 " >>crontab
crontab crontab -u root

[For some reason the above commands do not work for me, and I do the *wrong* thing and edit the crontab file by hand with the second line. Make a backup of your current crontab file - yes, I have even wiped it out accidentaly - before you perform these commands or make any changes.]

2.3 courier-imap

At first, the given configuration files can be used without modification.

sh -c ' \
  for i in imapd imapd-ssl imapd.cnf pop3d pop3d-ssl pop3d.cnf ; do \
  cp /usr/local/etc/courier-imap/$i.dist /usr/local/etc/courier-imap/$i ; \
done'

The POP3s and IMAP4s each require an SSL-certificate. You can create one by entering the following commands:

/usr/local/share/courier-imap/mkpop3dcert
/usr/local/share/courier-imap/mkimapdcert

Next, the supplied start script will be modified with the following hack.

perl -pi -e 's|(\$LIBAUTHMODULES) \\\n| \1 \$\{exec_prefix\}/bin/open_relay \\\n|g' \
  /usr/local/libexec/courier-imap/*.rc

Now the POP3s, IMAP4 and IMAP4s services are ready to start. In order to have the services start after a power-up or restart, the following shell scripts should be copied to the /usr/local/etc/rc.d directory:

rm /usr/local/etc/rc.d/courier-imap-imapd.sh.sample
rm /usr/local/etc/rc.d/courier-imap-pop3d.sh.sample
cd /usr/local/libexec/courier-imap/
install -m 755 imapd.rc /usr/local/etc/rc.d/imapd.sh
install -m 755 imapd-ssl.rc /usr/local/etc/rc.d/imapd-ssl.sh
install -m 755 pop3d-ssl.rc /usr/local/etc/rc.d/pop3d-ssl.sh
2.4 qmail-conf

The service scripts for POP3, SMTP and the distribution agent for the emails will be configured and installed:

/var/qmail/bin/qmail-pop3d-conf /usr/local/vpopmail/bin/vchkpw \
  qmaill /var/qmail/service/pop3d
cd /var/qmail/service/pop3d/
echo ":allow" >tcp
echo "200" > env/CONCURRENCY
make

/var/qmail/bin/qmail-smtpd-conf qmaild qmaill /var/qmail/service/smtpd
cd /var/qmail/service/smtpd/
echo "200" > env/CONCURRENCY
rm -f tcp.cdb tcp
ln -s /usr/local/vpopmail/etc/tcp.smtp.cdb /var/qmail/service/smtpd/tcp.cdb
ln -s /usr/local/vpopmail/etc/tcp.smtp /var/qmail/service/smtpd/tcp
rm Makefile

echo '#!/bin/sh' >/var/qmail/rc
echo 'exec env - PATH="/var/qmail/bin:$PATH" \' >>/var/qmail/rc
echo 'qmail-start ./Maildir/ /usr/local/bin/multilog t /var/log/qmail qmaill' >>/var/qmail/rc
chmod 755 /var/qmail/rc
/var/qmail/bin/qmail-delivery-conf qmaill /var/qmail/service/qmail
mkdir /var/log/qmail
chmod 750 /var/log/qmail
chown qmaill /var/log/qmail
2.5 daemontools

The program "svscan" [(the daemontools service)] searches through all of the subdirectories of a /service directory for a script called "run." The /service directory must be created and symbolic links made to the directories where the services are located that you want run.

mkdir /var/service
ln -s /var/qmail/service/pop3d /var/service/pop3d
ln -s /var/qmail/service/smtpd /var/service/smtpd
ln -s /var/qmail/service/qmail /var/service/qmail

The start script for "svscan" (i.e. daemontools) must be activated in order for svscan to work after a system reboot.

mv /usr/local/etc/rc.d/svscan.sh.sample /usr/local/etc/rc.d/0svscan.sh
chmod 744 /usr/local/etc/rc.d/0svscan.sh