Why install qmail the hard way.
There are other howto articles that explain how to install qmail with FreeBSD ports, and they will work fine.
You will have a completely installed qmail MTA, and not have a clue what how it works.
First to explain a little.
qmail will not be started like any other daemon such as Apache or Inetd.
qmail’s author D.J. Bernstein has also created other software packages, and one of them is daemontools.
You will start daemontools the traditional way, and it will start, and supervise your MTA software.
Another package that D.J. Bernstein has created is called ucspi-tcp.
It controls SMTP connections and allows you to control who may connect, and who may relay through your MTA.
So go out and get the needed software. You will need,
daemontools-0.76
ucspi-tcp-0.88
qmail-1.03
checkpassword-0.90
doublebounce-trim.patch ( This will instantly kill double bounces )
qmailqueue-patch ( This will cause any program that would run qmail-queue to look for an environment variable QMAILQUEUE )
Make a directory call /usr/local/src
# mkdir -p /usr/local/src
Install wget, it makes life easier.
# pkg_add -r wget
Get the files
# cd /usr/local/src
# wget http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
# wget http://cr.yp.to/software/qmail-1.03.tar.gz
# wget http://cr.yp.to/checkpwd/checkpassword-0.90.tar.gz
You will need to make a /package directory for daemontools, and put the archive in it.
# mkdir /package
# cd /package
# wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
Now set the sticky bit on the package directory.
# chmod 1755 /package
Now will unpack the source for all files
# umask 022
# gunzip daemontools-0.76.tar.gz ( Still in /package)
# tar xpf daemontools-0.76.tar
# cd /usr/local/src
# tar xzf ucspi-tcp-0.88.tar.gz
# tar xzf qmail-1.03.tar.gz
# tar xzf checkpassword-0.90.tar.gz
Now we have to make the directory where qmail will go.
# mkdir /var/qmail
Now we must create the users and groups that qmail will run as. (Fake prompt excluded for ease of copying)
pw groupadd nofiles
pw useradd qmaild -g nofiles -d /var/qmail -s /nonexistent
pw useradd alias -g nofiles -d /var/qmail/alias -s /nonexistent
pw useradd qmaill -g nofiles -d /var/qmail -s /nonexistent
pw useradd qmailp -g nofiles -d /var/qmail -s /nonexistent
pw groupadd qmail
pw useradd qmailq -g qmail -d /var/qmail -s /nonexistent
pw useradd qmailr -g qmail -d /var/qmail -s /nonexistent
pw useradd qmails -g qmail -d /var/qmail -s /nonexistent
Now we will install qmail itself, along with the patches
# cd /usr/local/src/qmail-1.03
# wget http://bsdzone.net/howto/qmail/patches/doublebounce-trim.patch
# wget http://bsdzone.net/howto/qmail/patches/qmailqueue-patch
# patch < doublebounce-trim.patch
# patch -p0 < qmailqueue-patch
# make setup check
Now we will configure qmail.
# ./config-fast yourfqdn
Now install ucspi-tcp
# cd /usr/local/src/ucspi-tcp-0.88
# make
# make setup check
Now install daemontools
# cd /package/admin/daemontools-0.76
# package/install
Now install checkpassword
# cd /usr/local/src/checkpassword-0.90
# make
# make setup check
Now that we have all the software installed, we must create the startup scripts for everything.
I use the scripts from lifewithqmail.
As a matter of fact you should also buy his book.
It is packed full of useful information about qmail.
I should also note that all scripts listed from this howto are protected under the OpenContent License
Now create this script under /var/qmail/rc.
Set the permissions on the script to 755
# chmod 755 /var/qmail/rc
Now you must choose a type of delivery for qmail. In this howto I will use Maildir.
This will limit the types of MUA / POP3d / IMAP that you can use.
# echo ./Maildir/ >/var/qmail/control/defaultdelivery
Now place the qmailctl script into /var/qmail/bin
Now set the permissions on the script, and link it to several places.
# chmod 755 /var/qmail/bin/qmailctl
# ln -s /var/qmail/bin/qmailctl /usr/bin
# ln -s /var/qmail/bin/qmailctl /usr/local/etc/rc.d/qmailctl.sh ( Will start qmail on reboot )
Now create the supervise directories for qmail ( Used by daemontools to start qmail )
# mkdir -p /var/qmail/supervise/qmail-send/log
# mkdir -p /var/qmail/supervise/qmail-smtpd/log
# mkdir -p /var/qmail/supervise/qmail-pop3d/log
Now create the supervise scripts
Create the /var/qmail/supervise/qmail-send/run script
Create the /var/qmail/supervise/qmail-send/log/run script
Create the /var/qmail/supervise/qmail-smtpd/run script
Create the /var/qmail/supervise/qmail-smtpd/log/run script
Create the /var/qmail/supervise/qmail-pop3d/run script
Create the /var/qmail/supervise/qmail-pop3d/log/run script
Now set the permissions for all the supervise scripts.
# 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
Now create the concurrencyincoming file ( Used by the /var/qmail/supervise/qmail-smtpd/run script )
# echo 20 > /var/qmail/control/concurrencyincoming
# chmod 644 /var/qmail/control/concurrencyincoming
Now create the logging directories for daemontools ( multilog )
( qmail does not use syslog, so you don’t need to configure syslog.conf or newsyslog.conf )
# mkdir -p /var/log/qmail/smtpd
# mkdir /var/log/qmail/pop3d
# chown qmaill /var/log/qmail /var/log/qmail/smtpd /var/log/qmail/pop3d
Now we will setup who may relay through the server, for now just add yourself.
# echo ‘127.:allow,RELAYCLIENT=""‘ >>/etc/tcp.smtp
Now setup who will be allowed to connect to your POP3d and check mail, I allow everyone
# echo ‘:allow’ > /etc/tcp.pop3
Now convert those files into something qmail understands.
# qmailctl cdb
Now we will disable Sendmail
# vi /etc/rc.conf
Change
sendmail_enable="NO” or sendmail_enable="YES”
to
sendmail_enable="NONE”
Save and exit
# ps -waux | grep sendmail
example:
smmsp 94 0.0 2.0 2936 1884 ?? Is 15Sep04 0:08.26 sendmail: Queue runner@00:30:00 for /var/spool/clientmqueue (sendmail)
root 91 0.0 2.2 3036 2068 ?? Ss 15Sep04 6:09.81 sendmail: accepting connections (sendmail)
root 4594 0.0 0.2 276 156 p0 R+ 2:10PM 0:00.00 grep sendmail
Kill all the sendmail PIDs
# kill 94
# kill 91
Now check to see if anything is still listening
# netstat -a | grep smtp
If you see
tcp4 0 0 localhost.smtp *.* LISTEN
you missed something, or you have another MTA running on the system. Kill it first.
Now move the old executables out of the way.
# mv /usr/libexec/sendmail/sendmail /usr/libexec/sendmail/sendmail.old
# mv /usr/sbin/sendmail /usr/sbin/sendmail.old
# chmod 0 /usr/sbin/sendmail.old /usr/libexec/sendmail/sendmail.old
Now link in qmail’s sendmail replacement
# ln -s /var/qmail/bin/sendmail /usr/libexec/sendmail/sendmail
# ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
Now create an alias for each required mailbox. Change username to the user where you want this mail to go.
# echo username > /var/qmail/alias/.qmail-root
# echo username > /var/qmail/alias/.qmail-postmaster
# echo username > /var/qmail/alias/.qmail-mailer-daemon
# chmod 644 /var/qmail/alias/.qmail-root /var/qmail/alias/.qmail-postmaster /var/qmail/alias/.qmail-mailer-daemon
Now you will want to setup your maildir ( Where your mail will be delivered )
Change to the user who own the mailbox
# su username
# maildirmake ~/Maildir
Now create your .qmail file
$ cd
$ echo ‘./Maildir/’ > .qmail
Change back to root
# exit
Now link your supervise scripts into the /service dir ( Should have been created by daemontools )
# ln -s /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-smtpd /var/qmail/supervise/qmail-pop3d /service
Qmail should start within 5 seconds, check to see if it is up
# qmailctl stat
/var/service/qmail-send: up (pid 13710) 1266411 seconds
/var/service/qmail-send/log: up (pid 222) 1270478 seconds
/var/service/qmail-smtpd: up (pid 13715) 1266411 seconds
/var/service/qmail-smtpd/log: up (pid 220) 1270478 seconds
/var/service/qmail-pop3d: up (pid 13725) 1266411 seconds
/var/service/qmail-pop3d/log: up (pid 225) 1270478 seconds
messages in queue: 0
messages in queue but not yet preprocessed: 0
If it is then send a test to yourself.
# echo to: username > /var/qmail/bin/qmail-inject
Check to see if it got there.
# cd /home/username/Maildir/new
# ls
You should see a file there, which is your message.
If not something during your install went wrong. Check your logs in /var/log/qmail
# cd /var/log/qmail
# tail -30 current | tai64nlocal
If everything worked okay, then allow your network to relay.
Add:
IP address of client:allow,RELAYCLIENT="”
to
/etc/tcp.smtp
then
# qmailctl cdb
You should now have a basic qmail setup up and running