Originally Published: Monday, 20 August 2001 Author: Henry Chen
Published to: enhance_articles_sysadmin/Sysadmin Page: 2/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.

Install Qmail  << Page 2 of 4  >>

Install Qmail (SMTP, POP)

As we are migrating from another server, we started with a clean Red Hat Linux 7.1 server installation with just the Web Server module.  I downloaded all the software into my home directory on the server.   Note:  for the truly lazy (or just very bad typist), copy the commands and paste them into your console window.

From your home directory, unpack the tarballs:

tar -xzf qmail-1.03.tar.gz
tar -xzf ucspi-tcp-0.88.tar.gz
tar -xzf checkpassword-0.90.tar.gz

There should now be subdirectories of these packages.  We start by doing Qmail.

su
umask 022
mkdir /var/qmail
ln -s /usr/local/man /var/qmail/man

I decided to leave the control and bin in the /var/qmail directory.  Otherwise, you can also do these:

mkdir /etc/qmail
ln -s /etc/qmail /var/qmail/control
ln -s /usr/sbin /var/qmail/bin

Now, we need to setup the Qmail groups and users:

/usr/sbin/groupadd nofiles
/usr/sbin/useradd alias -g nofiles -d /var/qmail/alias -s /nonexistent
/usr/sbin/useradd qmaild -g nofiles -d /var/qmail -s /nonexistent
/usr/sbin/useradd qmaill -g nofiles -d /var/qmail -s /nonexistent
/usr/sbin/useradd qmailp -g nofiles -d /var/qmail -s /nonexistent
/usr/sbin/groupadd qmail
/usr/sbin/useradd qmailq -g qmail -d /var/qmail -s /nonexistent
/usr/sbin/useradd qmailr -g qmail -d /var/qmail -s /nonexistent
/usr/sbin/useradd qmails -g qmail -d /var/qmail -s /nonexistent

The following will build Qmail from the sources:

cd qmail-1.03
make setup check
./config

For us, config works because we have a separate DNS server that has been humming along for ages.  If your DNS server some how doesn't get it, try this:

./config-fast the.full.hostname

Qmail is done.  Now we do ucspi-tcp.  You should still be the root user.  Note: $username is your username.

cd ~$username/ucspi-tcp-0.88
make
make setup check

ucspi-tcp is done.  This will install ucspi-tcp into the /usr/local/ directories.  Now daemontools.  You are still the root user:

mkdir -p /package
chmod 1755 /package
cd /package
tar -xzf ~$username/daemontools-0.76.tar.gz
cd admin/daemontools-0.76
package/install

daemontools is done.  At this point in time, you should see a few svsc... processes running (when you do a ps -ef).  Now checkpassword.  You are still the root user:

cd ~$username/checkpassword-0.90
make
make setup check

checkpassword is done.  We have made all the binaries that we need to run Qmail.  Next, we need create some configuration directories and files so that Qmail will run properly.

Configure

We are following the configuration suggestions made by Dave Sill (in Life with Qmail).  We have further made the decision to use Maildir instead of the other two less fancy options.  I am only going to discuss Maildir and not the other options.  Life with Qmail covers this configuration topic very well and very thoroughly.  I do not need to reinvent the wheel here.

In this section, you will need to create some files.  I use vi.  If you hate vi, anytime you see vi, just replace it with your favorite editor.  You are still be the root user.  First, we kill sendmail:

vi hint:  hit i for insert, the [ESC] key to end insert, and :x to save and exit.  If you made a mistake, hit [ESC] to stop whatever you are doing and :q! to exit without saving.

/etc/init.d/sendmail stop
rpm -e --nodeps sendmail

Removing sendmail completely is quite safe.  Qmail is more than capable of taking over for sendmail.  Now, we create all the directories that we need:

mkdir -p /var/log/qmail/smtpd
mkdir -p /var/log/qmail/pop3d
chown -R qmaill /var/log/qmail
mkdir -p /var/qmail/supervise/qmail-send/log
chmod +t /var/qmail/supervise/qmail-send
mkdir -p /var/qmail/supervise/qmail-smtpd/log
chmod +t /var/qmail/supervise/qmail-smtpd
mkdir -p /var/qmail/supervise/qmail-pop3d/log
chmod +t /var/qmail/supervise/qmail-pop3d

Now we create a rc file by vi /var/qmail/rc 

#!/bin/sh

# Using stdout for logging
# Using control/defaultdelivery from qmail-local to deliver messages by default

exec env - PATH="/var/qmail/bin:$PATH" \
qmail-start "`cat /var/qmail/control/defaultdelivery`"

Make this file executable, then create the defaultdelivery file:

chmod 755 /var/qmail/rc
echo ./Maildir/ > /var/qmail/control/defaultdelivery

Create the qmailctl file by vi /var/qmail/bin/qmailctl  

#!/bin/sh

# For Red Hat chkconfig
# chkconfig: - 30 80
# description: the qmail MTA


PATH=/var/qmail/bin:/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
export PATH

QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`

case "$1" in
  start)
    echo "Starting qmail"
    if svok /service/qmail-send ; then
      svc -u /service/qmail-send
    else
      echo qmail-send service not running
    fi
    if svok /service/qmail-smtpd ; then
      svc -u /service/qmail-smtpd
    else
      echo qmail-smtpd service not running
    fi
    if [ -d /var/lock/subsys ]; then
      touch /var/lock/subsys/qmail
    fi
    if svok /service/qmail-pop3d ; then
      svc -u /service/qmail-pop3d
    else
      echo qmail-pop3d service not running
    fi
    ;;
  stop)
    echo "Stopping qmail..."
    echo "  qmail-smtpd"
    svc -d /service/qmail-smtpd
    echo "  qmail-send"
    svc -d /service/qmail-send
    if [ -f /var/lock/subsys/qmail ]; then
      rm /var/lock/subsys/qmail
    fi
    echo "  qmail-pop3d"
    svc -d /service/qmail-pop3d
    ;;
  stat)
    svstat /service/qmail-send
    svstat /service/qmail-send/log
    svstat /service/qmail-smtpd
    svstat /service/qmail-smtpd/log
    qmail-qstat
    svstat /service/qmail-pop3d
    svstat /service/qmail-pop3d/log
    ;;
  doqueue|alrm|flush)
    echo "Sending ALRM signal to qmail-send."
    svc -a /service/qmail-send
    ;;
  queue)
    qmail-qstat
    qmail-qread
    ;;
  reload|hup)
    echo "Sending HUP signal to qmail-send."
    svc -h /service/qmail-send
    ;;
  pause)
    echo "Pausing qmail-send"
    svc -p /service/qmail-send
    echo "Pausing qmail-smtpd"
    svc -p /service/qmail-smtpd
    echo "Pausing qmail-pop3d"
    svc -p /service/qmail-pop3d
    ;;
  cont)
    echo "Continuing qmail-send"
    svc -c /service/qmail-send
    echo "Continuing qmail-smtpd"
    svc -c /service/qmail-smtpd
    echo "Continuing qmail-pop3d"
    svc -c /service/qmail-pop3d
    ;;
  restart)
    echo "Restarting qmail:"
    echo "* Stopping qmail-smtpd."
    svc -d /service/qmail-smtpd
    echo "* Sending qmail-send SIGTERM and restarting."
    svc -t /service/qmail-send
    echo "* Restarting qmail-smtpd."
    svc -u /service/qmail-smtpd
    echo "* Restarting qmail-pop3d."
    svc -t /service/qmail-pop3d
    ;;
  cdb)
    tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
    chmod 644 /etc/tcp.smtp.cdb
    echo "Reloaded /etc/tcp.smtp."
    ;;
  help)
    cat <<HELP
   stop -- stops mail service (smtp connections refused, nothing goes out)
  start -- starts mail service (smtp connection accepted, mail can go out)
  pause -- temporarily stops mail service (smtp connections accepted, but nothing leaves)
   cont -- continues paused mail service
   stat -- displays status of mail service
    cdb -- rebuild the tcpserver cdb file for smtp
restart -- stops and restarts smtp, sends qmail-send a TERM & restarts it
doqueue -- sends qmail-send ALRM, scheduling queued messages for delivery
 reload -- sends qmail-send HUP, rereading locals and virtualdomains
  queue -- shows status of queue
   alrm -- same as doqueue
  flush -- same as doqueue
    hup -- same as reload
HELP
    ;;
  *)
    echo "Usage: $0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}"
    exit 1
    ;;
esac

exit 0

Make qmailctl executable and link it to a whole bunch of places to make life easier when we need to manage Qmail later:

chmod 755 /var/qmail/bin/qmailctl
ln -s /var/qmail/bin/qmailctl /etc/init.d/qmail
ln -s /var/qmail/bin/qmailctl /usr/bin/qmailctl
ln -s ../init.d/qmail /etc/rc0.d/K30qmail
ln -s ../init.d/qmail /etc/rc1.d/K30qmail
ln -s ../init.d/qmail /etc/rc2.d/S80qmail
ln -s ../init.d/qmail /etc/rc3.d/S80qmail
ln -s ../init.d/qmail /etc/rc4.d/S80qmail
ln -s ../init.d/qmail /etc/rc5.d/S80qmail
ln -s ../init.d/qmail /etc/rc6.d/K30qmail

Now we do the supervise scripts for send.  First, vi /var/qmail/supervise/qmail-send/run

#!/bin/sh
exec /var/qmail/rc

Then send's log,  vi /var/qmail/supervise/qmail-send/log/run

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail

Now we do the supervise scripts for smtpd.  First,  vi /var/qmail/supervise/qmail-smtpd/run

#!/bin/sh
QMAILDUID=`id -u qmaild`
NOFILESGID=`id -g qmaild`
MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`
exec /usr/local/bin/softlimit -m 2000000 \
    /usr/local/bin/tcpserver -v -R -l 0 -x /etc/tcp.smtp.cdb -c "$MAXSMTPD" \
        -u "$QMAILDUID" -g "$NOFILESGID" 0 smtp /var/qmail/bin/qmail-smtpd 2>&1

Then, create the concurrencyincoming file:

echo 20 > /var/qmail/control/concurrencyincoming

Then smtpd's log,  vi /var/qmail/supervise/qmail-smtpd/log/run

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd

Now we do the supervise scripts for pop3d.  First,  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 /var/qmail/bin/qmail-pop3d Maildir 2>&1

FQDN is the Fully Qualified Domain Name of the server that you are working on.  

Then pop3d's log, vi /var/qmail/supervise/qmail-pop3d/log/run

#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/pop3d

Now make all these files executable:

chmod 755 /var/qmail/supervise/qmail-send/run
chmod 755 /var/qmail/supervise/qmail-send/log/run
chmod 755 /var/qmail/supervise/qmail-smtpd/run
chmod 755 /var/qmail/supervise/qmail-smtpd/log/run
chmod 755 /var/qmail/supervise/qmail-pop3d/run
chmod 755 /var/qmail/supervise/qmail-pop3d/log/run

Before we start up Qmail, we need to disallow relay from remote hosts (we will deal with relay control later) and setup some aliases.

echo '127.:allow,RELAYCLIENT=""' >> /etc/tcp.smtp 
qmailctl cdb
echo $username > /var/qmail/alias/.qmail-root
echo $username > /var/qmail/alias/.qmail-postmaster
ln -s .qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster

These are the bare minimum aliases.  Feel free to create more.  You should also see INSTALL.alias for more details on aliases.  You also need to populate the proper hostnames and domain names in the /var/qmail/control/locals and /var/qmail/control/rcpthosts.  At the bare minimum, you should have these:

localhost
hostname of your server

For virtual domains, you will need to populate /var/qmail/control/virtualdomains and create the proper .qmail-... file in the specific users' home directories.  You can find better discussions about virtual domains and all the fun and cool uses of .qmail files on the Qmail web site.

We have removed sendmail before.  Now, we replace it with Qmail's sendmail:

ln -s /var/qmail/bin/sendmail /usr/lib
ln -s /var/qmail/bin/sendmail /usr/sbin

Lastly (phew!), we link the run files to the /service directory (by linking the directories).  The /service directory was created by the daemontools' install script.  

ln -s /var/qmail/supervise/qmail-send /service
ln -s /var/qmail/supervise/qmail-smtpd /service 
ln -s /var/qmail/supervise/qmail-pop3d /service

Once these links are created, wait for a minute or two and Qmail will start running and you will have SMTP (send and receive) and POP.  For now, you also need to know these to start, stop and restart Qmail:

qmailctl start
qmailctl stop
qmailctl restart

Testing

That's it for Qmail. Now comes the fun part of testing.  Before you start testing, you need to create the proper "mailbox" for yourself, which is really a directory.  If you are still root, type exit to become yourself again, then do this:

cd
/var/qmail/bin/maildirmake Maildir

This will create a Maildir directory (in your home directory) with three sub-directories, cur, new and tmp.  When you send e-mail to yourself during testing, the new mail will appear in the new directory.

Follow the instructions in TEST.deliver and TEST.receive to verify that SMTP is working correctly.  To test POP, use any POP client to connect to this server to retrieve the e-mail that you have just sent yourself in TEST.receive.  I use Outlook Express to test this.  Remember to check the Leave copy of message on server box so that you do not delete the e-mails from the server (for testing IMAP later).

Also remember that you can only receive via POP now.  If you try to send anything via POP, Qmail will stop you (and you should test this to make sure).  If things does not work for you, don't freak out.  Check the /var/log/qmail directory and see what the logs tell you. 





Install Qmail  << Page 2 of 4  >>