$declare(String A = "<code><pre>")
$declare(String Z = "</pre></code>")
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Stand Blue Technology - Notes on installing qmail</title>
</head>
<body>
<a href="http://www.standblue.net/">Stand Blue Technology</a> -> 
<a href="/">projects.standblue.net</a> -> 
<b>qmail installation notes</b>

<h1>Notes on installing qmail</h1>
<p>
These instructions were written using Red Hat Linux and assume that the
user is logged in as root.  Read <a href="http://www.lifewithqmail.org/lwq.html">Life
with qmail</a> to get a understanding of how qmail works.  I do not
like the directories that LWQ uses (/var/qmail/supervise/qmail-send, etc)
so this page uses a more generic type of configuration. 
<p>
This guide is designed so that most of the commands and blocks of commands
can be directly copied and pasted into terminal windows, but you may need
to remove any leading whitespace on a line.

<p>
<h2>Sections</h2>
<ul>
  <li>Installation
    <ul>
      <li><a href="#software">Installed Software</a></li>
      <li><a href="#xsendmail">Removing sendmail</a></li>
      <li><a href="#installation">Downloading, Compiling and Installing</a></li>
      <li><a href="#configuration">Initial Configuration</a></li>
    </ul>
  </li>
  <li>Creating and Starting the Services
    <ul>
      <li><a href="#services">Service Directories</a></li>
      <li><a href="#service-qmail">The qmail Service</a></li>
      <li><a href="#service-smtpd">The smtpd Service</a></li>
      <li><a href="#service-pop3d">The pop3d Service</a></li>
      <li><a href="#service-resetproctitles">The resetproctitles Service</a></li>
    </ul>
  </li>
</ul>


<a name="software" />
<h2>Installed Software</h2>
<p>
Software that will be installed:
<ul>
  <li><a href="http://cr.yp.to/qmail.html">qmail</a></li>
  <li><a href="http://cr.yp.to/daemontools.html">daemontools</a></li>
  <li><a href="http://cr.yp.to/ucspi-tcp.html">ucspi-tcp</a></li>
  <li><a href="http://cr.yp.to/cdb.html">cdb</a></li>
  <li><a href="http://cr.yp.to/mess822.html">mess822</a></li>
  <li><a href="http://cr.yp.to/checkpwd.html">checkpassword</a></li>
$*  <li><a href="http://www.inter7.com/vpopmail/">vpopmail</a></li> *$
</ul>

<a name="xsendmail" />
<h2>Removing sendmail</h2>
<p>
First things first, find and remove the <code>sendmail</code> package
that was most likely installed with your operating system.  To find the
package names on Red Hat Linux or other RPM based distributions:

$(A)
  shell# rpm -qa|grep sendmail
  sendmail-doc-8.11.0-8
  sendmail-cf-8.11.0-8
  sendmail-8.11.0-8
$(Z)

To quickly remove all these packages:

$(A)
  shell# for i in `rpm -qa|grep sendmail`; do rpm -e --nodeps \$i; done
$(Z)


<a name="installation" />
<h2>Downloading, Compiling and Installing</h2>
<p>
With sendmail gone we can begin the qmail installation.  Create the 
<code>/package</code> and <code>/usr/local/src/email</code> directories:
$(A)
  mkdir /package
  mkdir /usr/local/src/email
$(Z)

Next, download all the necessary files by copying the following and pasting
it into your terminal:
$(A)
  cd /usr/local/src/email
  wget http://cr.yp.to/software/qmail-1.03.tar.gz
  wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
  wget http://cr.yp.to/cdb/cdb-0.75.tar.gz
  wget http://cr.yp.to/software/mess822-0.58.tar.gz
  wget http://cr.yp.to/checkpwd/checkpassword-0.90.tar.gz
$*  wget http://www.inter7.com/devel/vpopmail-5.3.12.tar.gz *$
  cd /package
  wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
$(Z)

Now all the necessary packages are downloaded.  The first thing to be installed
is daemontools.  

$(A)
  cd /package
  tar xzf daemontools-0.76.tar.gz
  cd admin/daemontools-0.76/
  package/install
$(Z)

On Linux systems svscanboot will start immediately, BSD systems will need to be
restarted.
<p>
Now switch back to the <code>/usr/local/src/email</code> directory to begin
installing the other utility packages:

$(A)
  cd /usr/local/src/email
  tar xzf mess822-0.58.tar.gz
  (cd mess822-0.58; make setup check)
  tar xzf cdb-0.75.tar.gz
  (cd cdb-0.75; make setup check)
  tar xzf ucspi-tcp-0.88.tar.gz
  (cd ucspi-tcp-0.88; make setup check)
  tar xzf checkpassword-0.90.tar.gz
  (cd checkpassword-0.90; make setup check)
$(Z)

The next step is to install qmail.  Unpack the tarball and cd to the
src directory:

$(A)
  tar xzf qmail-1.03.tar.gz
  cd qmail-1.03
$(Z)

Two steps need to be completed before qmail can be compiled.  First, the 
<code>/var/qmail</code> directory needs to be created, do this now:

$(A)
  mkdir /var/qmail
$(Z)

Second, the qmail users and groups need to be added to the system.  The
following is what I use on Red Hat Linux systems:

$(A)
  groupadd nofiles
  useradd -M -g nofiles -d /var/qmail/alias alias
  useradd -M -g nofiles -d /var/qmail qmaild
  useradd -M -g nofiles -d /var/qmail qmaill
  useradd -M -g nofiles -d /var/qmail qmailp
  groupadd qmail
  useradd -M -g qmail -d /var/qmail qmailq
  useradd -M -g qmail -d /var/qmail qmailr
  useradd -M -g qmail -d /var/qmail qmails
$(Z)

The -M flag is added to prevent the useradd program from copying
the contents of the /etc/skel directory to the users home directory.

<p>
Finally, compile and install qmail:

$(A)
  make setup check
$(Z)

<a name="configuration" />
<h2>Initial Configuration</h2>
<p>
The next step is to create the default configuration for qmail.  If your
machine has a valid name in DNS then run the <code>./config</code> command 
from the qmail source directory:

$(A)
  ./config
$(Z)

If DNS is not configured for the machine then use the <code>./config-fast</code>
command and pass the desired hostname as a parameter (replace host.example.com 
with your actual hostname):

$(A)
  ./config-fast host.example.com
$(Z)

Create the <code>root</code>, <code>postmaster</code> and <code>MAILER-DAEMON</code>
aliases to your account:

$(A)
  echo <i>youracct</i> &gt; /var/qmail/alias/.qmail-root 
  echo <i>youracct</i> &gt; /var/qmail/alias/.qmail-postmaster
  echo <i>youracct</i> &gt; /var/qmail/alias/.qmail-mailer-daemon
$(Z)

Now create symbolic links from <code>/var/qmail/bin/sendmail</code> in 
<code>/usr/sbin</code> and <code>/usr/lib</code> for compatibility with
existing applications:

$(A)
  ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
  ln -s /var/qmail/bin/sendmail /usr/lib/sendmail
$(Z)

<h2>Creating and Starting the Services</h2>

<a name="services" />
<h2>Service Directories</h2>
<p>
Create the master service directory and any subdirectories for services
that you may wish to run (smtpd, pop3d, etc):

$(A)
  mkdir /var/services
  mkdir -p /var/services/qmail/log
  mkdir -p /var/services/smtpd/log
  mkdir -p /var/services/pop3d/log
$(Z)

Also make any log directories for use with 
<a href="http://cr.yp.to/daemontools/multilog.html">multilog</a> from 
daemontools:

$(A)
  mkdir /var/log/qmail
  mkdir /var/log/smtpd
  mkdir /var/log/pop3d
  chown qmaill:nofiles /var/log/qmail /var/log/smtpd /var/log/pop3d
$(Z)

<a name="service-qmail" />
<h2>The qmail service</h2>

Before the qmail service is created a few decisions must be made.  The
biggest thing that needs to be decided is which type of mailstore is
to be used.  In general, the <a href="http://cr.yp.to/proto/maildir.html">Maildir</a>
format is more reliable and favored among qmail administrators.  Postfix, 
Exim and Courier all support the Maildir format as well.  Other options
are the traditional /var/spool/mail/\$USER style (which is mbox format)
and the ./Mailbox style (also mbox).  These instructions use the Maildir
format.  If you decide to use another format then a different pop3 server
will need to be installed, qmail-pop3d only supports Maildir format.
<p>
Use the <code>/var/qmail/bin/maildirmake</code> program to create Maildir's
for existing users:

$(A)
  setuidgid <i>someuser</i> /var/qmail/bin/maildirmake ~<i>someuser</i>/Maildir
$(Z)

Then create a Maildir in the /etc/skel directory so that when new users are
added to the system their Maildir's are created automatically:

$(A)
  /var/qmail/bin/maildirmake /etc/skel/Maildir
$(Z)

<p>
Switch to the qmail service directory and open up a file named "run" with
your favorite text editor:

$(A)
  cd /var/services/qmail
  vi run
$(Z)

Paste the following code into the editor (remove any leading spaces):

$(A)
  #!/bin/sh
  exec env - PATH="/var/qmail/bin:\$PATH" qmail-start ./Maildir/
$(Z)

Save the file and exit the editor.  Change the permissions on the file
to 755 (-rwxr-xr-x):

$(A)
  chmod 755 run
$(Z)

Now open up the ./log/run file with your editor and add the following (once 
again, remove all leading whitespace):

$(A)
  #!/bin/sh
  exec setuidgid qmaill multilog t s200000 n20 /var/log/qmail
$(Z)

Save, exit and change the permissions on the file:

$(A)
  chmod 755 ./log/run
$(Z)

The qmail service is ready to run.  To start it, simply create a symbolic
link in the /service directory:

$(A)
  ln -s /var/services/qmail /service/qmail
$(Z)

Within 5 seconds svscan will notice the new link and start the service.  It
can be controlled with the <a href="http://cr.yp.to/daemontools/svc.html">svc</a> 
command from the daemontools package.

<a name="service-smtpd" />
<h2>The smtpd service</h2>
<p>
If you wish to accept mail from the outside world via SMTP then a smtpd service
needs to be configured.  Switch to the <code>/var/services/smtpd</code> directory,
open up a file named "run" in your text editor and add the following:

$(A)
  #!/bin/sh

  PATH="/var/qmail/bin:\$PATH"
  export PATH

  QUID=`id -u qmaild`
  QGID=`id -g qmaild`
  SMTPLIMIT=`head -1 /var/qmail/control/concurrencyincoming`
  LOCAL=`head -1 /var/qmail/control/me`

  if [ -z "\$QUID" ]; then echo "QUID is empty in /var/services/smtpd/run"; exit 1; fi
  if [ -z "\$QGID" ]; then echo "QGID is empty in /var/services/smtpd/run"; exit 1; fi
  if [ -z "\$SMTPLIMIT" ]; then echo "SMTPLIMIT is empty in /var/services/smtpd/run"; exit 1; fi
  if [ -z "\$LOCAL" ]; then echo "LOCAL is empty in /var/services/smtpd/run"; exit 1; fi
  
  exec /usr/local/bin/softlimit -m 2000000 \
    /usr/local/bin/tcpserver -vR -l "\$LOCAL" -c "\$SMTPLIMIT" \
      -x /service/smtpd/tcp.cdb -u "\$QUID" -g "\$QGID" 0 smtp \
        /var/qmail/bin/qmail-smtpd 2>&1
$(Z)

Save, exit and change the permissions on the file to 755.

<p>
Now open up the ./log/run file with your editor and add the following:

$(A)
  #!/bin/sh
  exec setuidgid qmaill multilog t s200000 n20 /var/log/smtpd
$(Z)

Save, exit and change the permissions on the file to 755.

<p>
You will need to decide the maximum number of concurrent incoming smtp connections
you want to allow.  A safe default for this is 20.  Life with qmail established the
practice of using the nonstandard <code>/var/qmail/control/concurrencyincoming</code>
file, and I like it, so I will continue to use it here:

$(A)
  echo 20 > /var/qmail/control/concurrencyincoming
$(Z)

Next you should decide what IP ranges or networks you wish to allow to relay through
the mail server.  Many small networks will have 192.168.* addresses that should be
able to send mail through the qmail server.  These addresses or networks will need
to be added to the <a href="http://cr.yp.to/ucspi-tcp/tcprules.html">tcprules</a>
database so that tcpserver will know to tell qmail-smtpd to accept mail remote
domains.  Switch to the <code>/var/services/smtpd</code> directory, open a file
named "tcp" in your text editor and add something like this:

$(A)
  127.0.0.1:allow,RELAYCLIENT=""
  192.168.1.:allow,RELAYCLIENT=""
$(Z)

This allows 127.0.0.1 and all the computers with addresses that start with 192.168.1
to relay through the qmail server.  Before this is useful it needs to be compiled into
a <a href="http://cr.yp.to/cdb.html">cdb</a> database so that tcpserver can understand
it:

$(A)
  tcprules /service/smtpd/tcp.cdb /service/smtpd/tcp.tmp < /service/smtpd/tcp
$(Z)

The smtpd service is now ready to be started.  Once again, simply make a symbolic link
in the /service directory and within 5 seconds the service should start:

$(A)
  ln -s /var/services/smtpd /service/smtpd
$(Z)

<a name="service-pop3d" />
<h2>The pop3d service</h2>

In order to allow remote users to retrieve their local mail with MUA's such as Mozilla Mail
or Outlook a pop3d service will need to be configured.  I do not recommend allowing system
accounts to use pop3 because passwords are sent clear text over the network.  The prefered
way to store mail is with a tool such as <a href="http://www.inter7.com/vpopmail/">vpopmail</a>
or VMailMgr.  There are cases where offering pop3 service makes sense, so I will describe the
process below.

<p>
Switch to the <code>/var/services/pop3d</code> directory, open a file named "run" in your
text editor and add the following:

$(A)
  #!/bin/sh

  LOCAL=`head -1 /var/qmail/control/me`

  exec /usr/local/bin/softlimit -m 2000000 \
    /usr/local/bin/tcpserver -vHR -l "\$LOCAL" 0 pop3 \
      /var/qmail/bin/qmail-popup "\$LOCAL" /bin/checkpassword \
        /var/qmail/bin/qmail-pop3d Maildir 2>&1
$(Z)

Save, exit and change the permissions on the file to 755.

<p>
Now open up the ./log/run file with your editor and add the following:

$(A)
  #!/bin/sh
  exec setuidgid qmaill multilog t s200000 n20 /var/log/pop3d
$(Z)

Save, exit and change the permissions on the file to 755.

<p>
The pop3d service is now ready to be started.  Link it into the /service directory
and wait for it to start:

$(A)
  ln -s /var/services/pop3d /service/pop3d
$(Z)

There are many other checkpassword compatible interfaces that will work with qmail-popup.
See qmail.org's <a href="http://qmail.org/top.html#checkpassword">checkpassword section</a>
to see if one better suits your needs.

<a name="service-resetproctitles" />
<h2>The resetproctitles service</h2>

This is not qmail specific, but if you are reading instructions on how to set up qmail then
you most likely do not know much about daemontools either.  There is a program that is installed
with daemontools called <code>readproctitles</code>.  The purpose of <code>readproctitles</code>
is to report errors in the output of the <code>ps</code> command.  A sample of the output of
`ps ax|grep readproc`:

$(A)
  861 ?        S      0:00 readproctitle service errors: .......................
$(Z)

When everything is going smooth there will be no errors here, only a long line of dots.  The 
program is great for debugging the "run" scripts listed above, but there is a problem.  The
error messages will stay there until something else bumps them out of the way.  This is
annoying because you cant tell if you are still experiencing the problem or if the errors
are from long ago.  To remedy this I always create a service called "resetproctitles" that
will reset the readproctitle error string to all dots.  Here are the steps:

$(A)
  mkdir /var/services/resetproctitles
  cd /var/services/resetproctitles
  touch down
  echo '#!/bin/sh' > run
  echo echo -n \$(for i in `seq 1 500`; do echo -n .; done) >> run
  chmod 755 run
  ln -s /var/services/resetproctitles /service/resetproctitles
$(Z)

FreeBSD users should use the `jot 500 1` command instead of `seq 1 500`.  
When you want to clear the readproctitle message just issue the following:

$(A)
  svc -o /service/resetproctitles
$(Z)

<p>
That is all.
<p>
&lt;cwright at standblue.net&gt;

<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
</html>
