Setting up a selective relay Qmail server
by Ryan Troy <[email protected]>
This article is a step by step "How-To" about installing Qmail
version 1.03 on FreeBSD 3.4. There are four main steps that need to be
done:
- Remove Sendmail
- Compile Qmail from ports collection
- Install qpopper
- Configure Pine to use ./Mailbox format
1. Remove Sendmail
Ok we need to turn off sendmail before installing qmail, we are
going to edit the rc.conf file. Below is an example.
# vi /etc/defaults/rc.conf
Once rc.conf is opened, search for sendmail. You should
evenutally find the following:
sendmail_enable="YES" # Run the sendmail daemon (or NO).
sendmail_flags="-bd -q30m" # Flags to sendmail (if enabled)
Change the "YES" to "NO", then save your changes
and exit the editor.
The next step is to remove sendmail from the system. The sendmail
binary on a FreeBSD system lives in /usr/sbin/sendmail. Keep
in mind that the following does not actually remove the files, it simply
makes them non-executable, non-readable, and non-writeable.
# chmod 0 /usr/sbin/sendmail
Now move the sendmail binary out of the way:
# mv /usr/sbin/sendmail /usr/sbin/sendmail.bak
2. Compile Qmail from the ports collection
# cd /usr/ports/mail/qmail
# make
# make install
This will download the code from an FTP site, for if you haven't
copied the source files into /usr/ports/distfiles.
Next, we are going to setup some qmail options. The aim here is to
have qmail use ./Mailbox mail delivery structure at startup
of the system.
# cp /var/qmail/boot/home /var/qmail/rc
To provide qmail backward compatibility, a symbolic link needs to
be set from sendmail to the qmail installation.
# ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail
The next step is to create aliases for root, postmaster, and
mailer-daemon:
# cd /var/qmail/alias
# echo frank > .qmail-root
# echo frank > .qmail-postmaster
# echo frank > .qmail-mailer-daemon
You will also need the daemontools and ucspi-tcp ports/packages
installed as well. These are general-purpose utilities that enhance
qmail's functionality. We will be using supervise, accustamp, setuser,
and cyclog from the daemontools port, and tcpserver from the ucspi-tcp
port.
Install daemontools and ucspi-tcp as you would any other port:
# cd /usr/ports/sysutils/daemontools
# make install
# cd /usr/ports/sysutils/ucspi-tcp
# make install
Now would be a good time to install the rblsmtpd port:
# cd /usr/ports/mail/rblsmtpd
# make install
Now you need to create the directories that cyclog logs to:
# mkdir /var/log/qmail
# chown qmaill /var/log/qmail
# mkdir /var/log/qmail/qmail-smtpd
# chown qmaill /var/log/qmail/*
Note that a default configuration does not allow for ANY relaying,
even from localhost. To allow relaying from localhost and your local
network, you would have to use something like this:
127.0.0.1:allow,RELAYCLIENT=""
192.168.1.:allow,RELAYCLIENT=""
:allow
How this all works: by setting RELAYCLIENT we ignore the
/control/rcpthosts file. If someone tries to relay through your mail
server and there IP class isn't in the tcp.smtp file they will get an
error saying domain isn't in rcpthosts. So you must set all your IP
classes in the tcp.smtp file otherwise your clients wont be able to
send email through the server.
All the domains you want to accept email for must be listed in the
rcpthosts file, if you already have an installation of qmail and want
to create a rcpthosts file, run this line:
# sed 's/:.*//' <virtualdomains | cat - locals | sort >rcpthosts
After you've created your rules, you need to activate them. tcpserver
works by reading a cdb (database) file. You use the tcprules program to
build the database file from your /etc/tcp.smtp file. This
is accomplished by the following command:
# tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
Now we need an rc file for sysvinit it can be found here , this file
is for FREEBSD 3.4-STABLE you might have to edit it for your system.
Put this rc file in /usr/local/etc/rc.d and you can call it
whatever you would like. I call mine (qmail). To start qmail just
issue this command:
# /usr/local/etc/rc.d/qmail
Now qmail automatically puts a bootup file in /usr/local/etc/rc.d.
It's called qmail.sh, and it will make sure qmail starts when the box
gets rebooted.
3. Install qpopper
The first thing you will need to do is download the source and the
qmail patch. These should be available from ftp.qualcomm.com.
Next, apply the patch and compile qpopper:
# tar xvzf qpopper2.53.tar.Z
# tar qpopper2.53.patch.tar.gz
# cd qpopper2.53
# patch < /path/to/qpopper.patch
# ./configure
# make
# cp popper /usr/local/libexec/
Now the qmail-smtpd server is running lets edit the
/etc/inetd.conf file and uncomment this line to start the
pop3 server.
# pop3 stream tcp nowait root /usr/local/libexec/popper popper
# killall -HUP inetd
4. Make pine use ./Mailbox format
If your going to be using pine, you will need to find the global
pine.conf file. Mine is located in
/usr/local/etc.
To make pine see ./Mailbox you need to edit pine.conf
and change inbox-path=Mailbox. See the example below:
# vi /usr/local/etc/pine.conf
# Path of (local or remote) INBOX, e.g.,
# ={mail.somewhere.edu}inbox
# Normal Unix default is the local INBOX (usually
# /var/spool/mail/$USER).
inbox-path=Mailbox
Enjoy your selective relay qmail server! |