Originally Published: Monday, 20 August 2001 Author: Henry Chen
Published to: enhance_articles_sysadmin/Sysadmin Page: 3/4 - [Printable]

Install and Test Qmail with POP, IMAP and WebMail

Kill Sendmail? Are you kidding me? Well, no. In this first run original article Henry Chen provides us with free detailed step-by-step instructions for installing Qmail with Redhat 7.1, an alternative open source solution to your mail management needs.

  << Page 3 of 4  >>

Install Courier IMAP

You have downloaded the tarball earlier.  You are now yourself (NOT root).  From your home directory:

cd Courier-IMAP 1.3.9
./configure --without-authdaemon --without-authldap --mandir=/usr/local/man
make
make check
su
umask 022
make install
make install-configure

You have just made the Couried IMAP binaries from the sources.  Now you need to configure it so that it will start up right.

Configure

If you happen to read Courier IMAP's web page, you will see some discussion on virtual mailboxes, authdaemon, and Courier's POP.  We have a dedicated e-mail server here so we did not bother with virtual mailboxes.  As for authdaemon, this requires another process to be running in the background and we did not particularly feel like running another process.  We also like Qmail's POP better.  

You are now root.  You need to edit the IMAP configuration file: vi /usr/lib/courier-imap/etc/imapd

There are only a few things that need to be changed.  I am listing the lines that we changed:

ADDRESS=IP Address of your server
AUTHMODULES="authpam"
IMAP_CHECK_ALL_FOLDERS=1
IMAP_MOVE_EXPUNGE_TO_TRASH=1

Leave the other lines as default.  Only the ADDRESS and AUTHMODULES are essential.  We like the other two functions so because we want to mimic the Exchange 2000 server that we test drove.  Also, PAM is installed by default with Red Hat Linux 7.1.  Now make some links to make life easier:

ln -s /usr/lib/courier-imap/libexec/imapd.rc /etc/init.d/imapd
ln -s ../init.d/imapd /etc/rc0.d/K31imapd
ln -s ../init.d/imapd /etc/rc1.d/K31imapd
ln -s ../init.d/imapd /etc/rc2.d/S81imapd
ln -s ../init.d/imapd /etc/rc3.d/S81imapd
ln -s ../init.d/imapd /etc/rc4.d/S81imapd
ln -s ../init.d/imapd /etc/rc5.d/S81imapd
ln -s ../init.d/imapd /etc/rc6.d/K31imapd

We made the counter in the rc directories 1 greater than Qmail because we want to start Qmail first when we reboot.  To start (and stop) Courier IMAP, do this:

/etc/init.d/imapd start
/etc/init.d/imapd stop

Testing

Startup Courier IMAP and test it.  From any IMAP client (I use Outlook Express), once you set it up, it will look for IMAP folders from your server.  In /var/log/messages, you should also see a bunch of PAM authentication messages.   In the Inbox, you should see the messages from TEST.receive.  You should also be able to create new IMAP folders, subscribe/unsubscribe to these folders.  Furthermore, you should also be able to move messages to/from any folder to any other folder.

After you have created some IMAP folders, you can check to see what your Maildir directory looks like.  You should see several more directories (with a "dot" in the beginning of the directory name, i.e. you have to do ls -al to see them).

Install Relay-Ctrl

Now that SMTP, POP and IMAP all functions, we need to add the ability for Qmail to selectively relay e-mail for our customers so that they can set their incoming and outgoing e-mail server to be the same thing.  To accomplish this, we picked relay-ctrl from Bruce Guenter.  It is well written and simple to use.

You are still the root user.

cd ~$username
tar -xzf relay-ctrl-2.5.tar.gz
cd relay-ctrl-2.5

Before we make the binaries, we have to make some changes to correspond relay-ctrl to our prior installations.  Do vi relay-ctrl-age.c and make these changes:

const char* rulesdir = "/etc";
const char* smtprules = "tcp.smtp";
const char* smtpcdb = "tcp.smtp.cdb";
const char* tcprules = "/usr/local/bin/tcprules";

To make and install the binaries: 

make
make root-install

Now we edit the pop3d file by vi /var/qmail/supervise/qmail-pop3d/run 

#!/bin/sh
exec /usr/local/bin/softlimit -m 2000000 \
    /usr/local/bin/tcpserver -v -R -H -l 0 0 110 /var/qmail/bin/qmail-popup \
        FQDN /bin/checkpassword /usr/sbin/relay-ctrl-allow \
        /var/qmail/bin/qmail-pop3d Maildir 2>&1

Note where we inserted relay-ctrl.  Then, we change one line in the imapd file by vi /usr/lib/courier-imap/etc/imapd

AUTHMODULES="authpam relay-ctrl-allow"

Then, we setup a cron job to check the relay list every 3 minutes by crontab -e

*/3 * * * * /usr/sbin/relay-ctrl-age

Lastly, we create the proper links and directories 

ln -s /usr/sbin/relay-ctrl-allow /usr/lib/courier-imap/libexec/authlib
mkdir /var/spool/relay-ctrl

Testing

Now you are able to make Qmail relay e-mail if you authenticate first through either POP or IMAP.  You should try this out with the POP and IMAP accounts that you have already setup.  When you authenticate, you should see a file with a filename of the IP address of your "remote" host show up in the /var/spool/relay-ctrl directory.  As long as this file exist, you will be able to relay e-mail using such host.  To properly test it, you should do POP first, see the file appear, delete it (you have to be root to do this), then do IMAP, and you should see the same IP address appear again.





  << Page 3 of 4  >>