QMAIL + VPOPMAIL for FreeBSD 3.x/4.0 Tutorial (v1.0) By Flattie McGee This HOW-TO will show you how to install the qmail Mail Transfer Agent (MTA) + Modules for use on a FreeBSD 3.x/4.x server. You will have the ability to use the following features: SMTP E-Mail Server POP3 Virtual/Local Domain Hosting POP3 Virtual/Local Domain Users AutoResponder Mailing List Web Based E-Mail Web Based Virtual/Local Domain/User Control Interface Spam Blocking SMTP/POP3/SEND logging You will install the following programs: qmail-1.03.tar.gz : qmail! daemontools-0.70.tar.gz : Useful tools ucspi-tcp-0.88.tar.gz : Inetd replacement vpopmail-3_4_11-2_released_tar.gz : Virtual Domain/POP module ezmlm-0_53_tar.gz : Mailing List module autorespond-1_0_0_tar.gz : Auto Responder module gdbm-1.8.0.tar.gz : Database routines qmailadmin-0.30pre1.tar.gz : Web Control Interface Make Users & Groups for Qmail & Vpopmail # pw groupadd -n nofiles -g 81 # pw groupadd -n qmail -g 82 # pw useradd -n alias -u 81 -g 81 -d /var/qmail/alias -s /nonexistent # pw useradd -n qmaild -u 82 -g 81 -d /var/qmail -s /nonexistent # pw useradd -n qmaill -u 83 -g 81 -d /var/qmail -s /nonexistent # pw useradd -n qmailp -u 84 -g 81 -d /var/qmail -s /nonexistent # pw useradd -n qmailq -u 85 -g 82 -d /var/qmail -s /nonexistent # pw useradd -n qmailr -u 86 -g 82 -d /var/qmail -s /nonexistent # pw useradd -n qmails -u 87 -g 82 -d /var/qmail -s /nonexistent # pw groupadd -n vchkpw -g 88 # pw useradd -n vpopmail -u 88 -g 88 -c Vpopmail-Master -d /home/vpopmail -s /nonexistent Make Users & Directories for Logging and Special Modules # mkdir /var/qmail # mkdir /var/log/qmail /var/log/qmail/qmail-send # mkdir /var/log/qmail/qmail-smtpd /var/log/qmail/qmail-pop3d # chown -R qmaill.wheel /var/log/qmail # chmod -R 750 /var/log/qmail # mkdir /service /var/qmail/supervise # mkdir /var/qmail/supervise/qmail-smtpd /var/qmail/supervise/qmail-smtpd/log # chmod +t /var/qmail/supervise/qmail-smtpd # mkdir /var/qmail/supervise/qmail-send /var/qmail/supervise/qmail-send/log # chmod +t /var/qmail/supervise/qmail-send # mkdir /var/qmail/supervise/qmail-pop3d /var/qmail/supervise/qmail-pop3d/log # chmod +t /var/qmail/supervise/qmail-pop3d Install Qmail (Our saviour) # ftp koobera.math.uic.edu (anonymous login) # cd www/software/ # get qmail-1.03.tar.gz # quit # tar zxvf qmail-1.03.tar # cd qmail-1.03 # pico conf-split replace # 200 # pico conf-spawn replace # with 255 # make setup check # ./config Install Daemon Tools (Useful tools) # ftp koobera.math.uic.edu (anonymous login) # cd daemontools # get daemontools-0.70.tar.gz # tar zxvf daemontools-0.70.tar.gz # cd daemontools-0.70 # make # make setup check Install UNIX Client-Server Program Interface for TCP (Inetd replacement) # ftp koobera.math.uic.edu (anonymous login) # cd ucspi-tcp # get ucspi-tcp-0.88.tar.gz # quit # tar zxvf ucspi-tcp-0.88.tar.gz # cd ucspi-tcp-0.88 # make # make setup check # cp tcpserver /usr/local/bin # cp tcprules /usr/local/bin Installing Vpopmail (Virtual Domain & POP) # tar zxvf vpopmail-3_4_11-2_released_tar.gz # cd vpopmail-3.4.11-2.released # ./configure --enable-roaming-users=y --enable-logging=y --enable-hardquota=15000000000 --enable-ip-alias-domains=y # make # make install-strip # crontab -e 40 * * * * /home/vpopmail/bin/clearopensmtp 2>&1 > /dev/null # echo 255 > /var/qmail/control/concurrencyremote # chmod 644 /var/qmail/control/concurrencyremote Install AutoResponders (Just what is says) # ftp koobera.math.uic.edu (anonymous login) # cd www/software/ # get # quit # tar zxvf autorespond-1_0_0_tar.gz # cd autorespond-1_0_0_tar # gcc -Wall -o autorespond autorespond.c # cp autorespond /usr/local/bin Install Ezmlm (Mailing List) # ftp koobera.math.uic.edu (anonymous login) # cd www/software/ # get ezmlm-0_53_tar.gz # quit # tar zxvf ezmlm-0_53_tar.gz # cd ezmlm-0.53 # make # make man # make setup Install QmailAdmin (Web Control Interface) # ftp koobera.math.uic.edu (anonymous login) # cd www/software/ # get qmailadmin-0.30pre1.tar.gz # quit # tar zxvf qmailadmin-0.30pre1.tar.gz # cd qmailadmin-0.30pre1 # ./configure # make # make install-strip Install GDBM (Database Routines) # ftp ftp.gnu.org (anonymous login) # cd /gnu/gdbm/ # get gdbm-1.8.0.tar.gz # quit # ./configure # make # make install Install Sqwebmail (Web Based Email Checking) # ftp courier.sourceforge.net/ # cd pub/courier/sqwebmail # get sqwebmail-0_36_37pre1_tar.gz # quit # ./configure -with-cachedir -enable-webpass=vpopmail -with-module=authvchkpw # make configure-check # make # make check # make install # crontab -e 40 * * * * /usr/local/share/sqwebmail/cleancache.pl 2>&1 > /dev/null # chmod -R 755 /usr/local/apache/htdocs/webmail # chmod -R a+rx /usr/local/share/sqwebmail At this point in time, we'll start to add, remove and edit configuration files. We will also accomplish a number of other fun things. Edit System files (edit /etc/services and verify/add the line below) pop3 110/tcp # Post Office # pico /etc/tcp.smtp 127.0.0.1:allow,RELAYCLIENT="" 198.168.1.:allow,RELAYCLIENT="" 200.200.200.:allow,RELAYCLIENT="" :allow # /usr/local/bin/tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp # chmod 644 /etc/tcp.smtp.cdb # echo username > /var/qmail/alias/.qmail-root # echo username > /var/qmail/alias/.qmail-postmaster # echo username > /var/qmail/alias/.qmail-mailer-daemon # /var/qmail/bin/maildirmake /usr/share/skel/Maildir Disable Sendmail # pico /etc/defaults/rc.conf sendmail_enable="NO" sendmail_flags="-bd -q30m" # chmod 0 /usr/sbin/sendmail # mv /usr/sbin/sendmail /usr/sbin/sendmail.bak # ln -s /var/qmail/bin/sendmail /usr/sbin/sendmail Edit DNS zone file # pico domain.com.db $TTL 86400 @ IN SOA server.domain.com. root.domain.com. ( 20000524 ; Serial 3600 ; Refresh 900 ; Retry 3600000 ; Expire 3600 ) ; Minimum @ IN NS ns.domain.com. server.domain.com. IN A 200.200.200.201 mail IN A 200.200.200.202 domain.com. IN MX 10 mail Add POP Domain IP # ifconfig x10 inet 200.200.200.202 netmask 255.255.255.0 alias and/or # pico /etc/rc.conf ifconfig_xl0_alias1="alias 200.200.200.202 netmask 255.255.255.0" Adding Domains For this example, we will add a domain "domain.com" # cd /home/vpopmail/bin # ./vadddomain domain.com or # ./vadddomain domain.com password-for-postmaster vadddomain will modify the following qmail files (default locations used) : /var/qmail/control/locals /var/qmail/control/rcpthosts /var/qmail/control/morercpthosts (if rcpthosts > than 50 lines) /var/qmail/control/virtualdomains /var/qmail/users/assign /var/qmail/users/cdb It will also create a domains directory ~vpopmail/domains/domain.com ~vpopmail/domains/domain.com/postmaster/Maildir ... ~vpopmail/domains/domain.com/vpasswd ~vpopmail/domains/domain.com/vpasswd.cdb If you do not specify a password on the command line, it will prompt for a password for the postmaster. Then it will send a kill -HUP signal to qmail-send telling it to re-read the control files. Note: setting up DNS MX records for the virtual domain is not covered in this INSTALL file. Delete a virtual domain # cd ~vpopmail/bin # ./vdeldomain domain.com Adding a pop user # cd ~vpopmail/bin # ./vadduser newuser@domain.com or # ./vadduser newuser@domain.com In the case where the domain is specified (user@domain.com), the user is added to the ~vpopmail/domains/domain.com directory. If you don't enter a password on the command line, it will prompt for a password. Delete a pop user # cd ~vpopmail/bin # ./vdeluser newuser@domain.com (for the domain.com virtualdomain example) Changing a pop users password # cd ~vpopmail/bin # ./vpasswd newuser@domain.com Supervise/Svscan Startup # pico /var/qmail/rc #!/bin/sh env env - PATH="/var/qmail/bin:/usr/local/bin" \ qmail-start ./Maildir/ -- # pico /var/qmail/supervise/qmail-pop3d/run #!/bin/sh exec /usr/local/bin/tcpserver -H -R -v -c100 0 110 /var/qmail/bin/qmail-popup server.domain.com \ /home/vpopmail/bin/vchkpw /var/qmail/bin/qmail-pop3d Maildir 2>&1 # chmod 751 run # pico /var/qmail/supervise/qmail-pop3d/log/run #!/bin/sh exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-pop3d 2>&1 # chmod 751 run -- # pico /var/qmail/supervise/qmail-smtdp/run #!/bin/sh exec /usr/local/bin/tcpserver -p -R -x /etc/tcp.smtp.cdb -u82 -g81 -v -c100 0 smtp rblsmtpd /var/qmail/bin/qmail-smtpd 2>&1 # chmod 751 run # pico /var/qmail/supervise/qmail-smtpd/log/run #!/bin/sh exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-smtpd 2>&1 # chmod 751 run -- # pico /var/qmail/supervise/qmail-send/run #!/bin/sh exec /var/qmail/rc # chmod 751 run # pico /var/qmail/supervise/qmail-send/log/run #!/bin/sh exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-send 2>&1 # chmod 751 run -- # pico /usr/local/etc/rc.d/qmail #! /bin/sh #PATH=/var/qmail/bin:/usr/local/bin:/usr/bin:/bin #export PATH case "$1" in start) echo -n "Starting qmail: svscan" cd /var/qmail/supervise env - PATH="/var/qmail/bin:/usr/local/bin:/usr/bin:/bin" svscan & echo $! > /var/run/svscan.pid echo "." ;; stop) echo -n "Stopping qmail: svscan" kill `cat /var/run/svscan.pid` echo -n " qmail" svc -dx /var/qmail/supervise/* echo -n " logging" svc -dx /var/qmail/supervise/*/log echo "." ;; stat) cd /var/qmail/supervise svstat * */log ;; doqueue|alrm) echo "Sending ALRM signal to qmail-send." svc -a /var/qmail/supervise/qmail-send ;; queue) qmail-qstat qmail-qread ;; reload|hup) echo "Sending HUP signal to qmail-send." svc -h /var/qmail/supervise/qmail-send echo "Sending HUP signal to qmail-pop3d." svc -h /var/qmail/supervise/qmail-pop3d ;; pause) echo "Pausing qmail-send" svc -p /var/qmail/supervise/qmail-send echo "Pausing qmail-smtpd" svc -p /var/qmail/supervise/qmail-smtpd echo "Pausing qmail-pop3d" svc -p /var/qmail/supervise/qmail-pop3d ;; cont) echo "Continuing qmail-send" svc -c /var/qmail/supervise/qmail-send echo "Continuing qmail-smtpd" svc -c /var/qmail/supervise/qmail-smtpd echo "Continuing qmail-pop3d" svc -c /var/qmail/supervise/qmail-pop3d ;; restart) echo "Restarting qmail:" echo "* Stopping qmail-smtpd." svc -d /var/qmail/supervise/qmail-smtpd echo "* Sending qmail-send SIGTERM and restarting." svc -t /var/qmail/supervise/qmail-send echo "* Restarting qmail-smtpd." svc -u /var/qmail/supervise/qmail-smtpd echo "* Sending qmail-pop3d SIGTERM and restarting." svc -t /var/qmail/supervise/qmail-pop3d ;; cdb) tcprules /etc/tcp.smtp.cdb /etc/tcp.smtp.tmp < /etc/tcp.smtp chmod 644 /etc/tcp.smtp* echo "Reloaded /etc/tcp.smtp." ;; *) echo "Usage: $0 {start|stop|restart|doqueue|reload|stat|pause|cont|cdb|queue}" exit 1 esac exit 0 # chmod 751 qmail # ln -s /var/qmail/supervise/* /service/ Clean Directories (start fresh - DANGEROUS) # cd qmail-smtpd # cd supervise ; rm -rf * ; cd .. ; rmdir supervise ; cd log/supervise ; rm -rf * ; cd .. ; rmdir supervise ; cd .. Kill logs # cd /var/log/qmail ; cd qmail-pop3d ; rm -rf * ; cd .. ; cd qmail-send ; rm -rf * ; cd .. ; cd qmail-smtpd ; rm -rf * ; cd .. What you should see in the process list: root 25919 0.0 0.6 856 368 p0 S 12:16AM 0:00.18 svscan root 25920 0.0 0.5 812 336 p0 I 12:16AM 0:00.02 supervise qmail-smtpd root 25921 0.0 0.5 812 336 p0 I 12:16AM 0:00.02 supervise log root 25922 0.0 0.5 812 336 p0 I 12:16AM 0:00.02 supervise qmail-send root 25923 0.0 0.5 812 336 p0 I 12:16AM 0:00.02 supervise log root 25924 0.0 0.5 812 336 p0 I 12:16AM 0:00.02 supervise qmail-pop3d root 25925 0.0 0.5 812 336 p0 I 12:16AM 0:00.02 supervise log qmaill 25926 0.0 0.5 824 312 p0 I 12:16AM 0:00.03 /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-send qmaild 25927 0.0 0.7 852 444 p0 I 12:16AM 0:00.02 /usr/local/bin/tcpserver -p -R -x /etc/tcp.smtp.cdb -u82 -g81 -v -c10 qmaill 25928 0.0 0.5 824 312 p0 I 12:16AM 0:00.02 /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-smtpd root 25929 0.0 0.5 608 308 p0 I 12:16AM 0:00.01 /bin/sh /var/qmail/rc qmaill 25930 0.0 0.5 824 312 p0 I 12:16AM 0:00.02 /usr/local/bin/multilog t s100000 n20 /var/log/qmail/qmail-pop3d qmails 25931 0.0 0.7 892 444 p0 I 12:16AM 0:00.15 qmail-send root 25932 0.0 0.5 836 332 p0 I 12:16AM 0:00.01 /usr/local/bin/tcpserver -H -R -v -c100 0 110 /var/qmail/bin/qmail-po root 25933 0.0 0.6 840 356 p0 I 12:16AM 0:00.01 qmail-lspawn ./Maildir/ qmailr 25934 0.0 0.5 840 336 p0 I 12:16AM 0:00.01 qmail-rspawn qmailq 25935 0.0 0.6 824 372 p0 I 12:16AM 0:00.01 qmail-clean Other Tidbits: Convert Multilog datestamps to human readable datestamps # cat qmaillog | tai64nlocal > qmaillog.tmp # tai64nlocal < qmaillog > qmaillog.tmp AmaViS - A Mail Virus Scanner (not complete) ./configure --enable qmail --notifyreceiver=yes --enable-logging=yes --with-logdir="/var/log/qmail/anti-virus/" --with-virusdir="/var/qmail/anti-virus -with-mailto-root@globelinks.com --enable-x-header Download Metamail http://bmrc.berkeley.edu/~trey/emacs/metamail.html