Qmail Installation on RHEL5

1 Software Pre-requisites

Apache Web Server

Perl –any version  of 5

GCC – the gcc compiler

wget – use for downloading installers

patch & patchutils

 2  Download the source files

wget http://www.qmail.org/netqmail-1.05.tar.gz

wget ftp://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz

wget ftp://cr.yp.to/daemontools/daemontools-0.76.tar.gz

mkdir -p /usr/local/src

mv netqmail-1.05.tar.gz ucspi-tcp-0.88.tar.gz /usr/local/src

mkdir -p /package

mv daemontools-0.76.tar.gz /package

chmod 1755 /package

cd /usr/local/src

tar zxvf  netqmail-1.05.tar.gz

cd netqmail-1.05

./collate.sh  # watch for errors here

cd ..

tar zxvf ucspi-tcp-0.88.tar.gz

cd /package

tar zxvf daemontools-0.76.tar.gz

3  Create directories

mkdir /var/qmail

3.1 Create users and groups

cd /usr/local/src/netqmail-1.05/netqmail-1.05

You can check the INSTALL.ids to setup qmail groups and users, to make it easy you just copy these commands

groupadd nofiles

useradd -g nofiles -d /var/qmail/alias alias

useradd -g nofiles -d /var/qmail qmaild

useradd -g nofiles -d /var/qmail qmaill

useradd -g nofiles -d /var/qmail qmailp

groupadd qmail

useradd -g qmail -d /var/qmail qmailq

useradd -g qmail -d /var/qmail qmailr

useradd -g qmail -d /var/qmail qmails

3.2  Do the build

cd /usr/local/src/netqmail-1.05/netqmail-1.05

make setup check

./config-fast the.full.hostname(for ex. ./config-fast phi.freelinuxtutorials.com)

4 Install ucspi-tcp

cd /usr/local/src/ucspi-tcp-0.88

patch < /usr/local/src/netqmail-1.05/other-patches/ucspi-tcp-0.88.errno.patch


make setup check

 5 Install daemontools

cd /package/admin/daemontools-0.76

cd src

patch < /usr/local/src/netqmail-1.05/other-patches/daemontools-0.76.errno.patch

cd ..


6 Start qmail

6.1 Use an editor to create /var/qmail/rc script

vim /var/qmail/rc and then use this script:


# 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`”

6.2 Execute these commands:

chmod 755 /var/qmail/rc

mkdir /var/log/qmail

6.3 Create a default delivery mode for messages that aren’t delivered by a .qmail file. Type:

echo ./Maildir/ >/var/qmail/control/defaultdelivery

 7 Create a startup/shutdown script like the following in /var/qmail/bin/qmailctl


# For Red Hat chkconfig

# chkconfig: – 80 30

# description: the qmail MTA


export PATH

QMAILDUID=`id -u qmaild`

NOFILESGID=`id -g qmaild`

case “$1″ in


echo “Starting qmail”doqueue|alrm|flush)

echo “Flushing timeout table and sending ALRM signal to qmail-send.”


svc -a /service/qmail-send







echo “Sending HUP signal to qmail-send.”

svc -h /service/qmail-send



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



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



echo “Restarting qmail:”

echo “* Stopping qmail-smtpd.”

svc -d /service/qmail-smtpd /service/qmail-smtpd/log

echo “* Sending qmail-send SIGTERM and restarting.”

svc -t /service/qmail-send /service/qmail-send/log

echo “* Restarting qmail-smtpd.”

svc -u /service/qmail-smtpd /service/qmail-smtpd/log

echo “* Restarting qmail-pop3d.”

svc -t /service/qmail-pop3d /service/qmail-pop3d/log



tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp

chmod 644 /etc/tcp.smtp.cdb

echo “Reloaded /etc/tcp.smtp.”

tcprules /etc/tcp.pop3.cdb /etc/tcp.pop3.tmp < /etc/tcp.pop3

chmod 644 /etc/tcp.pop3.cdb

echo “Reloaded /etc/tcp.pop3.”



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 (connections accepted, 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 — schedules queued messages for immediate 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




echo “Usage: $0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}”

exit 1



exit 0

This script is available via http://www.lifewithqmail.org/qmailctl-script-dt70

7.1 Make the qmailctl script executable and link it to a directory in your path:

chmod 755 /var/qmail/bin/qmailctl

ln -s /var/qmail/bin/qmailctl /usr/bin

 8 The supervise scripts

8.1 Now create the supervise directories for the qmail services:

mkdir -p /var/qmail/supervise/qmail-send/log

mkdir -p /var/qmail/supervise/qmail-smtpd/log

8.2. Create the /var/qmail/supervise/qmail-send/run file:


exec /var/qmail/rc

8.3 Create the /var/qmail/supervise/qmail-send/log/run file:


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

8.4 Create the /var/qmail/supervise/qmail-smtpd/run file:


QMAILDUID=`id -u qmaild`

NOFILESGID=`id -g qmaild`

MAXSMTPD=`cat /var/qmail/control/concurrencyincoming`

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

if [ -z “$QMAILDUID” -o -z “$NOFILESGID” -o -z “$MAXSMTPD” -o -z “$LOCAL” ]; then


echo /var/qmail/supervise/qmail-smtpd/run

exit 1


if [ ! -f /var/qmail/control/rcpthosts ]; then

echo “No /var/qmail/control/rcpthosts!”

echo “Refusing to start SMTP listener because it’ll create an open relay”

exit 1


exec /usr/local/bin/softlimit -m 2000000 \

/usr/local/bin/tcpserver -v -R -l “$LOCAL” -x /etc/tcp.smtp.cdb -c “$MAXSMTPD” \

-u “$QMAILDUID” -g “$NOFILESGID” 0 smtp /var/qmail/bin/qmail-smtpd 2>&1

 8.5 Create the concurrency incoming control file:

echo 20 > /var/qmail/control/concurrencyincoming

chmod 644 /var/qmail/control/concurrencyincoming

8.6 Create the /var/qmail/supervise/qmail-smtpd/log/run file:


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

 8.6 Make the run 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

Then set up the log directories:

mkdir -p /var/log/qmail/smtpd

chown qmaill /var/log/qmail /var/log/qmail/smtpd

Finally, link the supervise directories into /service:

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

The /service directory is created when daemontools is installed.

 8.7  SMTP Access Control

Allow the local host to inject mail via SMTP:

echo ’127.:allow,RELAYCLIENT=””‘ >>/etc/tcp.smtp

qmailctl cdb

You can add here IP address that will allow to relay to outside domain. These entries ensure that your mail server is not an open relay.

9 Stop and disable the installed MTA

If you’re using an RPM-based Linux distribution like Red Hat, removing the MTA package might cause problems down the road. Utilities that update the system might try to reinstall Sendmail, or MUA packages might not install because they can’t tell an MTA is installed.

You can use Mate Wierdl’s stub package called “fake_mta” that can be installed to prevent these problems. Simply install the RPM available from http://www.csi.hu/mw/fake_mta-1-1memphis.noarch.rpm.

A.9.1 Download the said rpm and install the package

rpm –ivh fake_mta-1-1memphis.noarch.rpm

If your existing MTA is Sendmail, you should be able to stop it by running the init.d script with the “stop” argument. E.g., one of these should work:

/etc/init.d/sendmail stop

/etc/rc.d/init.d/sendmail stop

kill PID¬of¬sendmail

rpm ¬e –nodeps sendmail

Lastly, replace any existing /usr/lib/sendmail with the qmail version:

mv /usr/lib/sendmail /usr/lib/sendmail.old                  # ignore errors

mv /usr/sbin/sendmail /usr/sbin/sendmail.old                # ignore errors

chmod 0 /usr/lib/sendmail.old /usr/sbin/sendmail.old        # ignore errors

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

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

10 Create System Aliases
There are three system aliases that should be created on all qmail installations:

Alias                            Purpose
postmaster                   RFC 2821 required, points to the mail adminstrator (you)
mailer-daemon             de facto standard recipient for some bounces
root                              redirects mail from privileged account to the system administrator

To create these aliases, decide where you want each of them to go (a local user or a remote address) and create and populate the appropriate .qmail files. For example, say local user dave is both the system and mail administrator:

echo darwin > /var/qmail/alias/.qmail-root

echo darwin > /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

11 Start qmail

If you stopped qmail above after creating the links in /service, you should restart it now:
qmailctl start

qmail should now be running. First run qmailctl stat to verify that the services are up and running:

# qmailctl stat
/service/qmail-send: up (pid 30303) 187 seconds
/service/qmail-send/log: up (pid 30304) 187 seconds
/service/qmail-smtpd: up (pid 30305) 187 seconds
/service/qmail-smtpd/log: up (pid 30308) 187 seconds
messages in queue: 0
messages in queue but not yet preprocessed: 0

All four services should be “up” for more than a second. If they’re not, you’ve probably got a typo in the associated run script or you skipped one or more steps in creating the necessary files, directories, or links. Go back through the installation step-by-step and double check your work. You can also download and run the inst_check script, available from http://lifewithqmail.org/inst_check.

For example:

# sh inst_check
! /var/log/qmail has wrong owner, should be qmaill
…try: chown qmaill /var/log/qmail
If inst_check finds problems, fix them and re-run it. When everything looks right, inst_check will report:


About Manish Jha

Hi All I am Manish Kumar Jha aka Alex Hunt. I am currently working in VMware Software India Pvt Ltd as Operations System Engineer (vCloud Air Operations). I have around 5 Years of IT experience and have exposure on VMware vSphere, vCloud Director, RHEL and modern data center technologies like Cisco UCS and Cisco Nexus 1000v and NSX. If you find any post informational to you please press like and share it across social media and leave your comments if you want to discuss further on any post. Disclaimer: All the information on this website is published in good faith and for general information purpose only. I don’t make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this blog is strictly at your own risk. The Views and opinions published on this blog are my own and not the opinions of my employer or any of the vendors of the product discussed.
This entry was posted in Server Configuration. Bookmark the permalink.

One Response to Qmail Installation on RHEL5

  1. Pingback: Qmail Installation on RHEL5 | Linux/Vmware Solutions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s