!!!WARNING!!!
This HOWTO - which should be renamed the "qmail quick, uninformed install guide" is horribly outdated. Please see lifewithqmail.org for better and nore up-to-date instructions or help!
SF 2005-11-30
(with support for vqadmin, qmailadmin and sqwebmail)
Steven N. Fettig
See Creative Commons Copyright for copyright details.
Rev 1: 14 May 2004
This howto is very similar to the one I started translating a few years back from Oliver Lehman and is intended for people running FreeBSD 4.9 and up (it may work on lower versions, but I have not tested it and make no implied guarantee that it will work either way). I have found that a number of items in Oliver's howto didn't fit my needs, so I altered the HOWTO accordingly. Firstly, I don't totally understand the ssl certs, so I have not taken the time to make sure they are compiled/created correctly. The qmail and patchset I install includes the tls version of qmail and the courier-imap version I install will handle connections over ssl. I have installed and reinstalled various versions of qmail, vpopmail and courier-imap on the test server and have hosed certain portions of the installation. I have things working well, however, for new domains and intend to do a rebuild with the ssl support.
Assumptions:
- You have a fair grasp of FreeBSD and how to move around the filesystem.
- You can install services/programs via the ports.
- You understand that incorrectly configured email systems can be used as spam gateways - if you don't understand how to test and make sure you have NOT set up an open relay, STOP. Do us all a favor and learn/test/learn before placing a server on the net that is open to spammers.
- I don't know what I am doing half of the time.
- You may need to modify parts of these instructions to get this service combination to work on your machine.
- The smtp-auth patch will only work with vpopmail 5.4 and above.
- I use /usr/ports/distfiles/qmail/ as my SRC directory for compiling and installing software not installed via the ports.
Chapter 1 - Installation of Services
1.1 qmail
Install netqmail-1.05-tls with smtpauth patch (installation instructions are right in the text of the beginning of the patch):
cd /usr/ports/distfiles/qmail
fetch http://qmail.org/netqmail-1.05.tar.gz
fetch http://shupp.org/patches/netqmail-1.05-tls-smtpauth-20040207.patch
tar -xzvf netqmail-1.05.tar.gz
cd netqmail-1.05
./collate.sh
patch -p0 < ../netqmail-1.05-tls-smtpauth-20040207.patch
cd netqmail-1.05
mkdir /var/qmail
pw groupadd nofiles
pw useradd alias -g nofiles -d /var/qmail/alias -s /nonexistent
pw useradd qmaild -g nofiles -d /var/qmail -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
make
make setup check
rm /usr/sbin/sendmail
cp /var/qmail/bin/sendmail /usr/sbin/sendmail
Set sendmail_enable="YES" to sendmail_sendmail="NONE" in /etc/rc.conf
1.2 ucspi-tcp
ucspi-tcp is used so that use of inetd can be avoided in setting up tcp port connections. There are plenty of resources showing why people don't like inetd and I suggest you look for them on google.com.
There is a diff patch applied to rblsmtpd.c from Alan Curry so that "rblsmtpd works with A records." Same as Oliver's instructions:
cd /usr/ports/sysutils/ucspi-tcp
make extract
cd `make -VWRKDIR`
fetch http://www.qmail.org/ucspi-rss.diff
patch
cd -
make install clean
1.3 daemontools
Daemontools is used to start and log the services we are going to set up. In our case, daemontools only watches qmail, pop3 services and the smtp services. Courier-imap is started via sh scripts. I, personally, like daemontools, but people have made good arguments for and against its use. DJB is a person that people seem to love to hate or love to love, so some of the comments pro or contra are juvenile. So, decide for yourself whether you want to employ daemontools for other items.
cd /usr/ports/sysutils/daemontools
make all install clean
cd /usr/local/etc/rc.d
mv svscan.sh.sample 0svscan.sh
mkdir /var/service
1.4 vpopmail
vpopmail administers virtual domains. This allows you to set up multiple domains on one host and has many tools to go along with it (also from vpopmail's makers, inter7) that allow you to add and remove users/domains/etc. with very little effort.
1.5 courier-imap
courier-imap is the service used to allow for imap access to email accounts. It is also an inter7 invention.
If you want to make the ssl certificates you need to follow Oliver's instructions:
sh -c ' \
for i in imapd imapd-ssl imapd.cnf pop3d pop3d-ssl pop3d.cnf ; do \
cp /usr/local/etc/courier-imap/$i.dist /usr/local/etc/courier-imap/$i ; \
done'
/usr/local/share/courier-imap/mkpop3dcert
/usr/local/share/courier-imap/mkimapdcert
Like I said in the beginning - I don't understand enough about ssl to know whether this is the *right thing* or whether it will give you a false sense of security if connecting to imap and pop3 via ssl.
1.6 ezmlm-idx
If you want to enable your server for mailing lists, ezmlm-idx makes this very, very easy.
1.7 qmail-conf
From Tetsu Ushijima's website:
What is it?
qmail-conf is a collection of tools for setting up various qmail services. They are like *-conf programs in djbdns.
With qmail-conf, for example, setting up a minimal SMTP service takes the following four steps:
qmail-smtpd-conf qmaild qmaill /var/qmail/service/smtpd
cd /var/qmail/service/smtpd
make
ln -s /var/qmail/service/smtpd /service
qmail-conf assumes that (recent versions of) daemontools and ucspi-tcp have already been installed. It also assumes that svscan is already running.
qmail-conf tries to provide reasonable defaults: it avoids DNS reverse lookups; it avoids IDENT lookups; it lets TCP connection attempts be logged with multilog; and for POP3 and QMQP, connection attempts are denied unless you explicitly authorize your clients.
qmail-conf reduces the need for editing ./run scripts by using envdir. For example, to raise the concurrency limit for the SMTP connection to 100, all you have to do is:
echo 100 > /service/smtpd/env/CONCURRENCY
svc -t /service/smtpd
qmail-conf does not help you set up /var/qmail/alias, /var/qmail/control, /var/qmail/rc, and /var/qmail/users.
We will end up modifying the vanilla smtp run script so that we can enable smtp-auth. BUT, these -conf scripts have made the creation of run scripts for qmail extremely easy.
cd /usr/ports/distfiles/qmail
fetch http://www.din.or.jp/~ushijima/qmail-conf/qmail-conf-0.60.tar.gz
fetch http://cr.yp.to/djbdns/djbdns-1.05.tar.gz
tar -xzf qmail-conf-0.60.tar.gz
cd qmail-conf-0.60
tar -xzf ../djbdns-1.05.tar.gz
make -f Makefile.ini
make
make setup check
Chapter 2 - Configuration of start scripts, vpopmail, smtp-auth and courier-imap
2.1 vpopmail crontab script
vpopmail is automatically sets up a selective relay when a user authenticates via pop3. We need to make sure that the tcp.smtp under /usr/local/vpopmail/etc is "cleaned" every 40 minutes.
Add the following line to your favorite root, vpopmail OR system crontab:
40 * * * * /usr/local/vpopmail/bin/clearopensmtp >/dev/null 2>&1
if adding to the system crontab:
40 * * * * root /usr/local/vpopmail/bin/clearopensmtp >/dev/null 2>&1
2.2 Make the courier-imap startup scripts readable
The courier-imap port sets up install scripts in /usr/local/etc/rc.d that aren't yet readable at boot time because they are appended by the name .sample. We are simply going to copy the default the same name while removing the .sample ending.
mv /usr/local/etc/rc.d/courier-imap-imapd.sh.sample /usr/local/etc/rc.d/courier-imap-imapd.sh
mv /usr/local/etc/rc.d/courier-imap-pop3d-ssl.sh.sample /usr/local/etc/rc.d/courier-imap-pop3d-ssl.sh
cp /usr/local/etc/courier-imap/authdaemonrc.dist /usr/local/etc/courier-imap/authdaemonrc
You should take a quick look at the authdaemonrc file and take note of the configuration changes you can make.
To increase the number of concurrent sessions per IP, change the default value of imapd under /usr/local/etc/courier-imap
cd /usr/local/etc/courier-imap
ee imapd
Look through the file for MAXPERIP and change to a value you think will be reasonable for your needs. I need to be able to access 10 plus accounts at any given time, so I set mine to a high number of 20. You may not need to change this value, but it might become important if you find your clients timing out all the time.
2.3 Create the qmail control files and start scripts
We will start by creating the control files and dot postmaster files:
touch /var/qmail/alias/.qmail-postmaster \
/var/qmail/alias/.qmail-root \
/var/qmail/alias/.qmail-mailer-daemon
echo "" > /var/qmail/control/locals
hostname > /var/qmail/control/me
hostname | sed "s/`hostname -s`.//g" > /var/qmail/control/defaultdomain
hostname | sed "s/`hostname -s`.//g" > /var/qmail/control/plusdomain
We also need to make sure that the rcpthosts file is created so that the smtp server does not act as an open relay:
touch /var/qmail/control/rcpthosts
The following commands are almost identical to Oliver's, but I do not want to go though the hack to set up the selective relaying through vpopmail because I want to use auth-smtp. Also, we are going to edit the qmail-smtp run file afterwards. I still go through this process because I am not a good script writer and I like to see what someone else thinks is going to be a good run script.
/var/qmail/bin/qmail-pop3d-conf /usr/local/vpopmail/bin/vchkpw \
qmaill /var/qmail/service/pop3d
cd /var/qmail/service/pop3d/
echo ":allow" >tcp
echo "200" > env/CONCURRENCY
make
/var/qmail/bin/qmail-smtpd-conf qmaild qmaill /var/qmail/service/smtpd
cd /var/qmail/service/smtpd/
echo "200" > env/CONCURRENCY
echo '#!/bin/sh' >/var/qmail/rc
echo 'exec env - PATH="/var/qmail/bin:$PATH" \' >>/var/qmail/rc
echo 'qmail-start ./Maildir/ /usr/local/bin/multilog t /var/log/qmail qmaill' >>/var/qmail/rc
chmod 755 /var/qmail/rc
/var/qmail/bin/qmail-delivery-conf qmaill /var/qmail/service/qmail
mkdir /var/log/qmail
chmod 750 /var/log/qmail
chown qmaill /var/log/qmail
Now, go into /var/qmail/service/smtpd and we will change the run file:
cd /var/qmail/service/smtpd/
mv run run.orig
ee run
Copy the following into run:
#!/bin/sh
exec /usr/local/bin/softlimit -m 4000000 tcpserver -H -l0 -R -c 512 -x \
/usr/local/vpopmail/etc/tcp.smtp.cdb -u VCHKPWUID -g VCHKPWGID 0 smtp \
/var/qmail/bin/qmail-smtpd mail.yourdomain.tld \
/usr/local/vpopmail/bin/vchkpw /usr/bin/true &
and replace VCHKPWUID and VCHKPWGID with the appropriate UID and GID for vchkpw. Also replace mail.yourdomain.tld with your domain or fdqn of the server.
Now, create symlinks to the /var/service/ directory for qmail, pop3d and smtpd
ln -s /var/qmail/service/pop3d /var/service/pop3d
ln -s /var/qmail/service/smtpd /var/service/smtpd
ln -s /var/qmail/service/qmail /var/service/qmail
There are a number of ways you can proceed. Either start each of the start scripts you have installed under /usr/local/etc/rc.d manually or reboot the system. The next chapter covers the basics of adding and removing domains/users and mailing lists.
3. Administration of vpopmail and ezmlm-idx
3.1 Adding/Removing Domains/Users
vpopmail offers a very easy interface with which you can add and remove both domains and users on the fly. The commands to do this are found under /usr/local/vpopmail/bin. If you run the commands directly with no options, the command will list the available switches and options that must be used with that command. Inter7's documentation is also a good source for information.
Add a domain:
vadddomain domain.tld
Add a user to that domain:
vadduser user@domain.tld
Create an alias domain:
vaddaliasdomain alias.tld domain.tld
Change a user's password:
vchangepw user@domain.tld
Delete a user:
vdeluser user@domain.tld
Delete domain:
vdeldomain domain.tld
There are also ways to specify directories other than the default (/usr/local/vpopmail/domains) to store the virtual domains and user files. I have found, however, that this isn't necessarily a better way to manage security because the domain has to still have vpopmail:vchkpw read/write priviledges, so until I can find a way to give the user AND vpopmail access to the domain information/users and not others, I see no reason to use this option.
3.2 ezmlm-idx mailing lists
These set of commands are taken directly from Oliver's howto - I have yet to use mailing lists although I have always had ezmlm-idx installed.
To set up a moderated list (TEST) whose moderator can be reached at user1@domain1.tld, do the following:
cd /usr/local/vpopmail/domains
ezmlm-make -rdug -5 user1@domain1.tld /usr/local/vpopmail/domains/domain1.tld/TEST \
/usr/local/vpopmail/domains/domain1.tld/.qmail-TEST TEST domain1.tld
ezmlm-sub /usr/local/vpopmail/domains/domain1.tld/TEST user1@domain1.tld
ezmlm-sub /usr/local/vpopmail/domains/domain1.tld/TEST/digest user1@domain1.tld
ezmlm-sub /usr/local/vpopmail/domains/domain1.tld/TEST/mod user1@domain1.tld
chown -h vpopmail.vchkpw ./domain1.tld/.qmail-TEST*
chown -R vpopmail.vchkpw ./domain1.tld/TEST
3.3 Using SMTP-AUTH
The whole purpose for rewriting this howto was that I wanted to include smtp-auth into the mix. I have constantly had troubles with the courier-imap hack that allowed for selective relaying, so I decided a better way to open up the smtp server for relaying for my clients was to set up smtp-auth. In order to use smtp-auth (especially for those using imap folders and cannot open the smtp relay via the old hack), you simply need to set your email client to use smtp-auth with one of the usernames and passwords of one of the domains you have installed. Remember, a valid username is user@domain.tld and not simply user. I use Mozilla Thunderbird as my main email client these days and have not had any problems using smtp-auth. The only issue I have is that it slows the sending of emails because the authentication adds a delay to being able to send out the email. I would rather have the security, however - and perhaps it is an issue that I will find some solution to at a later time.
4. Web Administration
This is the section that I have been long waiting to work on. Now that I have a need for it - i.e. my own startup ISP that needs some remote-management interfaces - I have worked to get vqadmin, qmailadmin and sqwebmail working (all from inter7, of course).
I installed apache13-modssl from the ports and did do anything special to get it running other than making sure the ssl service started so that I could test running all of the above services via ssl.
4.1 Install apache13-modssl
To start apache13 with ssl activated:
apachectl startssl
I have had problems getting apache and ssl to start with the installed start script (/usr/local/etc/rc.d/apache.sh) and have yet to take the time to look further into the fact that neither apache nor the ssl portion of apache will start automatically once the server has been rebooted.
4.2 Install vqadmin
4.3 Install qmailadmin
4.4 Install sqwebmail
I modified this installation a little so that it always runs over the ssl server. Although email is inherently insecure and open in nature, at least the web clients cannot be directly monitored.
You need to use the run scripts installed in /usr/local/etc/rc.d to test sqwebmail or reboot the machine.
There you have it... You should have a fully functioning email server.
