Qmail, vpopmail, qmailadmin, vqadmin quick install guide

cd /usr/ports/mail/qmail-smtp_auth+tls
make -DWITH_BIG_TODO_PATCH -DWITH_QMAIL_QUEUE_PATCH install disable-sendmail enable-qmail certificate clean
cp /var/qmail/boot/maildir /var/qmail/rc
cp /var/qmail/doc/mailer.conf.sample /etc/mail/mailer.conf

cd /usr/ports/mail/vpopmail
make -DWITH_MYSQL -DWITH_VALIAS -DWITH_QMAIL_EXT -DWITH_DOMAIN_QUOTAS -DWITH_MYSQL_LOG WITH_MYSQL_USER=vpopmail WITH_MYSQL_PASSWD=mypass WITH_MYSQL_DB=vpopmail install clean
chmod 4711 /usr/local/vpopmail/bin/vchkpw

Important: If you get login failed errors for smtp/pop/imap auth then make sure sure have chmodded vchkpw and the owner user and group are correct. They should be vpopmail:vchkpw.

cd /usr/ports/mail/courier-imap
make -DWITHOUT_PAM -DWITH_VPOPMAIL install install-configure clean

conf=`mktemp /tmp/confXXXXXXXX`
sed -e 's/authmodulelist="authcustom authuserdb authvchkpw authpwd"/authmodulelist="authvchkpw"/' /usr/local/etc/courier-imap/authdaemonrc > $conf
mv /usr/local/etc/courier-imap/authdaemonrc /usr/local/etc/courier-imap/authdaemonrc.bak
cp $conf /usr/local/etc/courier-imap/authdaemonrc

The courier-imap information above is relevant for version 3.x, see the update below for 4.x.

echo 'courier_imap_pop3d_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/courier-imap-pop3d.sh start

cp /usr/local/etc/courier-imap/pop3d.cnf.dist /usr/local/etc/courier-imap/pop3d.cnf
mkpop3dcert
echo 'courier_imap_pop3dssl_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/courier-imap-pop3d-ssl.sh start

echo 'courier_imap_imapd_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/courier-imap-imapd.sh start

cp /usr/local/etc/courier-imap/imapd.cnf.dist /usr/local/etc/courier-imap/imapd.cnf
mkimapdcert
echo 'courier_imap_imapdssl_enable="YES"' >> /etc/rc.conf
/usr/local/etc/rc.d/courier-imap-imapd-ssl.sh start

echo "smtp stream tcp nowait qmaild /var/qmail/bin/tcp-env tcp-env /var/qmail/bin/qmail-smtpd `hostname` /usr/local/vpopmail/bin/vchkpw /bin/true" >> /etc/inetd.conf

killall -HUP inetd
if [ $? -ne 0 ]; then inetd -wW; fi

At the mysql prompt run:

create database vpopmail;
grant all on vpopmail.* to vpopmail@localhost identified by 'mypass';

Web control panels:

cd /usr/ports/mail/qmailadmin
make install clean

cd /usr/ports/mail/vqadmin
make install clean

Update: The newer 4.x version of courier-imap is installed in a different way:

Install courier, and make a copy of /usr/local/sbin/courierlogger that is needed to install courier-imap. Then remove courier, for some reason the install of courier-imap fails if the courierlogger binary isn't in place but we don't need courier since the MTA job is handled by qmail.

cd /usr/ports/mail/courier

make install clean
cp /usr/local/sbin/courierlogger /usr/local/sbin/courierlogger.bak
pkg_delete -x courier

Courier now uses authlibs, so we need one, that's the vchkpw lib. You can also use the mysql authlib which will be faster but requires more configuration changes. The config files for the authentication modules are moved from /usr/local/etc/courier-imap to /usr/local/etc/authlib too.

cd /usr/ports/mail/courier-authlib-vchkpw
make install clean

Install courier-imap itself:

cd /usr/ports/mail/courier-imap
make install clean