Copyright © 2001, 2002, 2003, 2007 Aaron Hill
2007-11-25
Abstract
This document describes how to set up the
qmail mail transfer agent on a
FreeBSD
system. These
instructions are known to work with FreeBSD
versions 4.2 through to 6.2,
and it is expected they will work with versions earlier and
later than that range. This document is intended to be quite
minimalist. It contains only the raw instructions for installing
qmail under FreeBSD
distilled from the
qmail documentation. As such, it is
not a substitute for reading the documentation.
Table of Contents
You need a FreeBSD
system with the ports system installed. The machine should be
connectied to an active Internet connection.
You should always update the ports system before installing any new software from it, this will ensure you are getting the latest and most secure version of the software available. More information on how to use CVS to update the ports system is available at The FreeBSD Project.
Of course if you want to receive email from the Internet you
will need the FreeBSD
system listed in an MX record of a correctly
registered domain. The steps on how to do this will not be covered
in this document.
You will need to know the Fully Qualified Domain Name
(FQDN) of the FreeBSD
machine. This is basically the
DNS name of the machine. For example if your
server's name is known in DNS as mailserver.mydomain.com
when the
instructions below ask you to type the text
HOSTNAME
you should replace the word
HOSTNAME
with the word
mailserver
. Or when the instructions ask
you to enter the text DOMAIN
you should
replace that word with the words
mydomain.com
The following Installation instructions must be performed as
the user root
.
# cd /usr/ports/mail/qmail # make all install clean
Check the boxes for:
SMTP_AUTH_PATCH QMAILQUEUE_PATCH BIG_TODO_PATCH
Click qmail by running the script:
. After installation, enable# /var/qmail/scripts/enable-qmail
# cd /usr/ports/sysutils/ucspi-tcp # make all install clean
Check the boxes for:
man ssl
Click
.Make the following change to the file /etc/manpath.config
:
# echo "OPTIONAL_MANPATH /var/qmail/man" >> /etc/manpath.config
Then run:
# makewhatis
so that the manpages can be used immediately.
# echo "127.0.0.1:allow,RELAYCLIENT=\"\"" > /etc/tcp.smtp
At this point, if you have a LAN on which client machines will require access to the SMTP port to send email, add the network part of the LAN's IP address space. For example, if hosts on the LAN are in the range 192.168.0.1–192.168.0.254, issue this command:
# echo "192.168.0.:allow,RELAYCLIENT=\"\"" >> /etc/tcp.smtp
Finally, build the ruleset for tcpserver:
# echo :allow >> /etc/tcp.smtp # /usr/local/bin/tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp
Find the following line in dot.cshrc
:
set mail = (/var/mail/$USER)
and modify the file as follows:
#set mail = (/var/mail/$USER) setenv MAIL ~/Mailbox setenv MAILDIR ~/Maildir setenv MAILTMP ~/Maildir/tmp/tmpfile alias mail '/var/qmail/bin/maildir2mbox;/var/qmail/bin/qail' alias pine '/var/qmail/bin/maildir2mbox;/var/qmail/bin/pinq' alias elm '/var/qmail/bin/maildir2mbox;/var/qmail/bin/elq'
Append the following lines to the end of dot.shrc
MAIL=~/Mailbox MAILDIR=~/Maildir MAILTMP=~/Maildir/tmp/tmpfile export MAIL MAILDIR MAILTMP alias mail='/var/qmail/bin/maildir2mbox;/var/qmail/bin/qail' alias pine='/var/qmail/bin/maildir2mbox;/var/qmail/bin/pinq' alias elm='/var/qmail/bin/maildir2mbox;/var/qmail/bin/elq'
Execute the following commands for each existing user:
# cp -R /usr/share/skel/Maildir ~USERSNAME/ # chown -R USERSNAME ~USERSNAME/Maildir # cp /usr/share/skel/dot.qmail ~USERSNAME/.qmail # chown USERSNAME ~USERSNAME/.qmail
Determine the login shell for each user, and modify the startup file for that shell in the manner described above.
If you are confident that a user has not modified their .cshrc
and .shrc
files, you can just copy the files /usr/share/skel/dot.cshrc
and /usr/share/skel/dot.shrc
over the files ~USERNAME/.cshrc
and ~USERNAME/.shrc
.
Append the following lines to the end of /etc/rc.conf
to set some variables used in the qmail startup script to follow:
# qmail options qmail_smtp_enable="YES" qmail_pop_enable="YES" qmail_enable="YES"
In the following sections, HOSTNAME
refers to the name of the localhost, and can be determined by running:
# hostname -s
HOSTNAME.DOMAIN
refers to the machine's fully qualified domain name (FQDN), and can be determined with:
# hostname
Obviously, DOMAIN
refers to the domain in which the machine resides, and is the FQDN minus the HOSTNAME
part.
Create /var/qmail/rc
:
#!/bin/sh # # This script starts and stops the qmail mail functions. # # Suck in the configuration variables. if [ -r /etc/defaults/rc.conf ]; then . /etc/defaults/rc.conf source_rc_confs elif [ -r /etc/rc.conf ]; then . /etc/rc.conf fi case "$1" in start) case ${qmail_smtp_enable} in [Yy][Ee][Ss]) # Start the qmail smtp daemon /usr/local/bin/tcpserver -H -R -c 255 -x /etc/tcp.smtp.cdb \ -u 82 -g 81 0 25 /var/qmail/bin/qmail-smtpd & echo -n " qmail-smtp" ;; esac case ${qmail_pop_enable} in [Yy][Ee][Ss]) # Start the qmail pop daemon /usr/local/bin/tcpserver -H -R -c 255 0 110 \ /var/qmail/bin/qmail-popup HOSTNAME.DOMAIN \ /usr/local/bin/checkpassword /var/qmail/bin/qmail-pop3d \ Maildir & echo -n " qmail-pop" ;; esac case ${qmail_enable} in [Yy][Ee][Ss]) # Start qmail exec env - PATH="/var/qmail/bin:$PATH" \ qmail-start ./Maildir splogger qmail & echo -n " qmail" ;; esac ;; stop) # Stop the smtp daemon smtppid=`ps -axw | grep tcpserver | grep smtp | grep -v grep | awk '{ print $1 }'` if [ "$smtppid" != "" ]; then kill $smtppid echo -n " qmail-smtp" fi # Stop the pop daemon poppid=`ps -axw | grep tcpserver | grep popup | grep -v grep | awk '{ print $1 }'` if [ "$poppid" != "" ]; then kill $poppid echo -n " qmail-pop" fi # Stop qmail qmailpid=`ps -axw | grep qmail-send | grep -v grep | awk '{ print $1 }'` if [ "$qmailpid" != "" ]; then kill $qmailpid echo -n " qmail" fi ;; *) echo "Usage: `basename $0` {start|stop}" >&2 ;; esac exit 0
Make the script executable:
chmod 750 /var/qmail/rc
# echo HOSTNAME.DOMAIN > /var/qmail/control/rcpthosts # echo DOMAIN >> /var/qmail/control/rcpthosts
# echo HOSTNAME.DOMAIN > /var/qmail/control/locals # echo DOMAIN >> /var/qmail/control/locals
qmail will not send email directly to root
. Even if no one else is sending email to root
, the system is probably sending its daily checks to root
every night, so the barest minimum qmail setup requires an alias for root
:
# echo EMAILADDRESS > /var/qmail/alias/.qmail-root
EMAILADDRESS
is the real address to which you want root's mail sent. Alias files can contain multiple addresses, but each address must be on a separate line.
qmail does not natively support the /etc/mail/aliases
file, though it can be made to do so with an add-on package. Read /var/qmail/doc/INSTALL.alias
for details on how qmail handles aliases. As a minimum, set up aliases for root
(done above), postmaster
and mailer-daemon
.
The author of this document is Aaron Hill. Feel free to send details of any errors in this document by email.
Paul Hoadley converted this document from HTML to DocBook XML and back again.