Before I start any installation of any software, I like to create a working folder, where all the packages and patches and such will live.
mkdir /home/kurth/qmail
Next we grab the packages for netqmail and vpopmail.
wget http://www.qmail.org/netqmail-1.06.tar.gz
wget http://shupp.org/patches/netqmail-1.05-tls-smtpauth-20070417.patch
wget http://superb-east.dl.sourceforge.net/sourceforge/vpopmail/vpopmail-5.4.25.tar.gz
And get a few patches
http://inoa.net/qmail-tls/netqmail-1.05-tls-20070408.patch
Uncompress netqmail-1.06 and vpopmail-5.4.25 tarballs.
tar zfvx netqmail-1.06.tar.gz
tar zfvx vpopmail-5.4.25.tar.gz
Apply Patches
cd netqmail
patch -p1 < patch
Before we can compile and install netqmail, we'll need to create system users for the qmail daemons to run as.
sudo /usr/sbin/groupadd nofiles
sudo /usr/sbin/useradd qmaild -g nofiles -d /var/qmail -s /nonexistent
sudo /usr/sbin/useradd alias -g nofiles -d /var/qmail/alias -s /nonexistent
sudo /usr/sbin/useradd qmaill -g nofiles -d /var/qmail -s /nonexistent
sudo /usr/sbin/useradd qmailp -g nofiles -d /var/qmail -s /nonexistent
sudo /usr/sbin/groupadd qmail
sudo /usr/sbin/useradd qmailq -g qmail -d /var/qmail -s /nonexistent
sudo /usr/sbin/useradd qmailr -g qmail -d /var/qmail -s /nonexistent
sudo /usr/sbin/useradd qmails -g qmail -d /var/qmail -s /nonexistent
With the users created, proceed to compile and install netqmail-1.06.
cd netqmail-1.06
sudo make setup check
sudo ./config
That’s it. Yes. netqmail is installed. Not running or configured, but installed. Onwards to vpopmail!
Like qmail, vpopmail requires local groups and users to run under. Create them now.
sudo /usr/sbin/groupadd -g 89 vchkpw
sudo /usr/sbin/useradd -g vchkpw -u 89 vpopmail
Then enter the vpopmail-5.4.25 dir, compile and install.
cd ../vpopmail-5.4.25
sudo ./configure --enable-roaming-users
sudo make install
You many want to review the INSTALL file in the vpopmail-5.4.25 dir for additional configure options. The configure script requires root access, so it must be run with root privs. That should be it. vpopmail should be installed.
Now we need to create netqmail’s control files.
sudo su
echo '20' > /var/qmail/control/concurrencyincoming
echo './Maildir' > /var/qmail/control/defaultdelivery
echo 'my.domain.tld' > /var/qmail/control/defaultdomain
echo 'my.domain.tld' > /var/qmail/control/me
echo 'my.domain.tld' > /var/qmail/control/locals
echo 'my.domain.tld' > /var/qmail/control/rcpthosts
echo 'domain.tld' > /var/qmail/control/plusdomain
exit;
notice that I put the full local name in the locals file. This allows me to send email to root@my.domain.tld and have it delivered to the local root user.
Create the /var/qmail/rc file.
#!/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 the script executable
chmod 755 /var/qmail/rc
Setup system aliases. Replace ‘kurth’ with your email address or user.
sudo su
echo kurth > /var/qmail/alias/.qmail-root
echo kurth > /var/qmail/alias/.qmail-postmaster
echo kurth > /var/qmail/alias/.qmail-mailer-daemon
echo kurth > /var/qmail/alias/.qmail-abuse
chmod 644 /var/qmail/alias/.qmail-*
Remove sendmail evil. Replace with a softlink to netqmail’s sendmail replacement.
sudo yum remove sendmail
sudo ln -s /var/qmail/bin/sendmail /usr/lib
sudo ln -s /var/qmail/bin/sendmail /usr/sbin
Create the supervise scripts for qmail-smtpd, qmail-send and qmail-smtpd-submission
Create /service/qmail-send/run. This file simply starts the /var/qmail/rc under supervise.
#!/bin/sh
exec /var/qmail/rc
Start logging /service/qmail-send/log/run
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail
Create the /service/qmail-smtpd/run. Notice the softlimit amount has been increased to 20 Megabytes.
#!/bin/sh
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 QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
echo /var/qmail/supervise/qmail-smtpd/run
exit 1
fi
exec /usr/local/bin/softlimit -m 20000000 \
/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
Enable smptd /service/qmail-smtpd/log/run
#!/bin/sh
exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t /var/log/qmail/smtpd
Create /service/qmail-smtpd-submission/run. Submission (port 587) is often used by roaming clients to bypass provider blocks on normal smtp (port 25).
#!/bin/sh
QMAILDUID=`id -u vpopmail`
NOFILESGID=`id -g vpopmail`
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 QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
echo /var/qmail/supervise/qmail-smtpd/run
exit 1
fi
exec /usr/local/bin/softlimit -m 30000000 \
/usr/local/bin/tcpserver -v -H -R -l "$LOCAL" -c "$MAXSMTPD" \
-u "$QMAILDUID" -g "$NOFILESGID" 0 587 \
/var/qmail/bin/qmail-smtpd recordio /home/vpopmail/bin/vchkpw /usr/bin/true 2>&1
Enable logging by creating /service/qmail-smtpd-submission/log/run containing the following.
#!/bin/sh
PATH=/var/qmail/bin:/usr/local/bin:/usr/bin:/bin
export PATH
exec setuidgid qmaill multilog t s100000 n20 /var/log/qmail/qmail-smtpd-submission 2>&1
Make files executable.
chmod 755 /service/qmail-send/run
chmod 755 /service/qmail-send/log/run
chmod 755 /service/qmail-smtpd/run
chmod 755 /service/qmail-smtpd/log/run
chmod 755 /service/qmail-smtpd-submission/run
chmod 755 /service/qmail-smtpd-submission/log/run
At this point svscan should have picked up the newly created run scripts. After all this I like to pull down all /service/qmail-* services and restart them.
svc -t /service/*
We need a daemon to provide IMAPS and POP3S. dovecot is popular and supports ./Maildir/ out-of-the-box.
sudo yum install dovecot
Now we can finally create our first domain!
sudo /home/vpopmail/bin/vadddomain domain.tld password
domain.tld added!
sudo /home/vpopmail/bin/vadduser kurth@domain.tld password
and user kurth@domain.tld with password of password has been added. At this point you should send a test email to the account to ensure everything is working.
I use the tail command to watch all the logs at once.
sudo tail -f /var/log/qmail/current /var/log/qmail/smtpd/current /var/log/qmail/qmail-smtpd-submission
OK, we’re ready to create the init script and fire up your netqmail server for the first time! This is the init script I have used for quite a while. I believe it might be from The Qmail Handbook by Dave Sill, but I forgot long ago.
#!/bin/sh
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 /service/qmail-send/log
else
echo "qmail-send supervise not running"
fi
if svok /service/qmail-smtpd ; then
svc -u /service/qmail-smtpd /service/qmail-smtpd/log
else
echo "qmail-smtpd supervise not running"
fi
if [ -d /var/lock/subsys ]; then
touch /var/lock/subsys/qmail
fi
;;
stop)
echo "Stopping qmail..."
echo " qmail-smtpd"
svc -d /service/qmail-smtpd /service/qmail-smtpd/log
echo " qmail-send"
svc -d /service/qmail-send /service/qmail-send/log
if [ -f /var/lock/subsys/qmail ]; then
rm /var/lock/subsys/qmail
fi
;;
stat)
svstat /service/qmail-send
svstat /service/qmail-send/log
svstat /service/qmail-smtpd
svstat /service/qmail-smtpd/log
qmail-qstat
;;
doqueue|alrm|flush)
echo "Flushing timeout table and sending ALRM signal to qmail-send."
/var/qmail/bin/qmail-tcpok
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
;;
cont)
echo "Continuing qmail-send"
svc -c /service/qmail-send
echo "Continuing qmail-smtpd"
svc -c /service/qmail-smtpd
;;
restart)
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
;;
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 <
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
HELP
;;
*)
echo "Usage: $0 {start|stop|restart|doqueue|flush|reload|stat|pause|cont|cdb|queue|help}"
exit 1
;;
esac
exit 0