1 TITLE: Qmail and Cyrus Imap with virtual domains
2 LFS VERSION: Tested on LFS-4.0
3 AUTHOR: Ivo Schaap <ivo@thecourtofeden.org>
5 SYNOPSIS: How to install and configure a mail system that can
6 handle mail to multiple domains using virtual domains.
10 version 1.2 (16/10/2002)
12 - Changed LFS version from 3 to 4
13 - Added c-client to the list of prerequisites, there could be more deps !!
14 - Moved Berkeley DB there as well and version updated from 3.0.1 -> 4.0.14
15 - Moved cyrus-sasl-1.5.27 -> cyrus-sasl-2.1.9
16 - Moved cyrus-imapd-2.0.16 -> cyrus-imapd-2.1.9
17 - Added Transport Layer Security (TLS) support
18 - Added Openssl 0.9.6g
19 - Added Avmailgate 2.0.1.7
23 - Added SpamAssassin 2.43
24 - Added Vipul's Razor v2.20 + sdk 2.20
25 - Added F-prot Antivirus 3.12b
26 - Added Distributed Checksum Clearinghouse 1.1.15
27 - Added Anomy-sanitizer 1.55
28 - Added Various comments and command improvements
30 version 1.1 (12/15/2001)
42 4. Installation of Avmailgate
43 5. Installation of Qmail
44 6. Installation of Nail
45 7. Installation of Fcron
46 8. Installation of Procmail
47 9. Installation of SpamAssassin
48 10. Installation of Razor-agents
49 11. Installation of Razor-agents-sdk
50 12. Installation of F-Prot Antivirus
51 13. Installation of Distributed Checksum Clearinghouse
52 14. Installation of Anomy-sanitizer
53 15. Installation of Imap
54 16. Configuration of Qmail and Mailboxes
55 17. Configuration of Procmail
56 18. Starting up all processes
57 19. Monitoring the processes
58 20. Migrating mail from backups
59 21. Interesting readings
68 http://www.sleepycat.com/update/snapshot/db-4.0.14.tar.gz
71 ftp://ftp.cac.washington.edu/imap/c-client.tar.Z
75 ftp://ftp.openssl.org/source/openssl-0.9.6g.tar.gz
78 http://www.hbedv.com/files/antivir/release/avlxmgt.tgz
79 avmailgate-2.0.1.7-Linux-glibc
81 The free license can be ordered here:
82 http://www.antivir.de/order/privreg/order_e.htm
85 http://cr.yp.to/software/qmail-1.03.tar.gz
88 http://omnibus.ruf.uni-freiburg.de/~gritter/archive/nail/nail-10.0.tar.gz
91 http://fcron.free.fr/fcron-2.0.0.src.tar.gz
94 http://www.procmail.org/procmail-3.22.tar.gz
97 http://spamassassin.taint.org/released/Mail-SpamAssassin-2.43.tar.gz
100 http://razor.sourceforge.net/download/index.html
101 razor-agents-sdk-2.03.tar.gz
102 razor-agents-2.20.tar.gz
105 ftp://ftp.f-prot.com/pub/f-prot_3.12b.tar.gz
107 Distributed Checksum Clearinghouse:
108 http://www.rhyolite.com/anti-spam/dcc/source/dcc-dccproc.tar.Z
112 http://mailtools.anomy.net/dist/anomy-sanitizer-1.55.tar.gz
115 ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-imapd-2.1.9.tar.gz
116 ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.9.tar.gz
122 First of all I wanna thank Gerard and all the others for providing
123 the platform where we do the stuff we do.
125 In this hint we setup a mail server that serve two virtual example domains
126 and have different example users per domain:
128 - linuxfromsource.org
130 - John the Ripper john@linuxfromsource.org
131 - Susie Summer susie@linuxfromsource.org
132 - Dirk Beekmans dirk@linuxfromsource.org
135 - linuxfrombinary.org
137 - Olaf Olsen olaf@linuxfrombinary.org
138 - Jennifer Loopneus jennifer@linuxfrombinary.org
139 - Pamela Andersom pamela@linuxfrombinary.org
141 John is the local administer so he gets the mail for root, postmaster and
142 himself. All the usernames must be unique as each user has its own box so if
143 olaf have a email account on linuxfrombinary AND linuxfromsource he must
144 be the same person because its the same mailbox. And if Olaf opens his
145 mailbox he sees mail from both the domains. Comprende ?
147 There is also a cyrus user to administer the IMAP server daemon and the
148 mailboxes. But he got a password for both for unix and imap/sasl.
150 A mail user do not needs a unix password set to get mail. If one of the
151 mail users needs access on the mail server you give him a unix password
152 as well as the imap/sasl password.
162 Make sure there is an MX record in DNS to point mail for the virtual domains
163 to the host running qmail. (Mostly the DNS runs on the ISP side.)
165 This is what roughly happens:
167 Here is a mail to olaf@linuxfrombinary.org to your SMTP server.
169 The SMPT server wants to find out who is linuxfrombinary.org. An email address
170 as well as a web site address needs to be resolved in an ip address.
171 DNS ( Domain Name Server) is used to resolve the domain in an ip address
172 and point to a mail server that will accept connections.
173 An MX (mail exchange) record is used for that.
175 Now the mail is routed to your ip adders for your mail server on port 25.
176 Port 25 is your SMTP port that listens for mail from your domains.
177 Your IP address can be your fixed DSL ip address or a connection on your
178 campus, or other fixed ip address connections to the internet. If you behind
179 masquerading you need to set up forwarding rules for both smtp and imap. It
180 should be possible have a dynamic ip address domain name solution on the
181 internet from where you can host your mail server from dailup or isdn
188 UCB's database library version-4.0.14
189 Cyrus IMAP will not compile with the version of Berkeley DB 4.1.24.
190 Or maybe there is a patch for it. Let me know ;)
192 Use this to install it once your in the unpacked tarball of Berkeley DB.
198 make docdir=/usr/doc/Berkeley-DB all install
200 chown -R 0.0 /usr/doc/Berkeley-DB
201 chmod -R go-w /usr/doc/Berkeley-DB
204 C. c-client library (Optional)
205 --------------------------------
207 I have this already installed and this is imap related. Adjust to taste
208 this is what i used. Its only a static library with some headers for
209 development. (this is the minimum requirement for IMAP in PHP.
218 < SSLDIR=/usr/local/ssl
219 < SSLCERTS=$(SSLDIR)/certs
220 < SSLINCLUDE=$(SSLDIR)/include
221 < SSLLIB=$(SSLDIR)/lib
224 > SSLCERTS=/etc/ssl/certs
225 > SSLINCLUDE=/usr/include
228 < SPOOLDIR=/usr/spool
229 < MAILSPOOL=$(SPOOLDIR)/mail
230 < NEWSSPOOL=$(SPOOLDIR)/news
232 > SPOOLDIR=/var/spool
233 > MAILSPOOL=/var/mail
234 > NEWSSPOOL=/var/news
240 cp c-client.a /usr/lib &&
241 cp c-client.h /usr/include &&
242 cp imap4r1.h /usr/include &&
243 cp rfc822.h /usr/include &&
244 cp mail.h /usr/include &&
245 cp linkage.h /usr/include &&
246 cp env.h /usr/include &&
247 cp env_unix.h /usr/include &&
248 cp fs.h /usr/include &&
249 cp ftl.h /usr/include &&
250 cp misc.h /usr/include &&
251 cp nntp.h /usr/include &&
252 cp nl.h /usr/include &&
253 cp osdep.h /usr/include &&
254 cp smtp.h /usr/include &&
255 cp tcp.h /usr/include &&
256 ln -s /usr/lib/c-client.a /usr/lib/libc-client.a &&
257 ln -s /usr/lib/c-client.a /usr/lib/libc-client4.a
260 D. Open Secure Socket Layer
261 ---------------------------
263 We Only need it if you plan to use imap with ssl but its also needed
264 with Openssh so you might already have it.
266 cp Configure Configure.dist
268 vi +337 Configure # for optimization edit this file
276 mv doc/apps/passwd.pod doc/apps/openssl-passwd.pod
277 ./Configure linux-elf \
278 --openssldir=/etc/ssl \
280 make MANDIR=/usr/share/man all install
287 If any one know of other imap/mail deps, mail me, i have 70+ packs already
288 installed beyond lfs-4 when i start building this server.
289 In /path/to/cyrus-imapd-2.1.9/doc/install-prereq.html you find them all.
293 4. Installation of Avmailgate
294 ==============================
296 Avmailgate offers virus protection by having a daemon listening on port 25.
297 This is the SMPT port. When mail gets thru, it uses qmail's sendmail wrapper
298 to inject the mail into the qmail queue.
300 The other option is to have qmail's smtp server started from (x)inetd and
301 listening on port xxx where avmailgate is forwarding virus checked mail to.
302 But this gives only more rules for the firewall when heres an other port open.
305 cd /usr/src/avmailgate-2.0.1.7-Linux-glibc
307 mkdir /usr/lib/AntiVir
309 cp vdf/antivir.vdf /usr/lib/AntiVir
310 cp bin/antivir /usr/lib/AntiVir
312 chown -R daemon.daemon /usr/lib/AntiVir
314 cp etc/avmailgate.conf /etc
315 cp etc/avmailgate.acl /etc
316 cp etc/antivir.conf /etc
317 --------------------------------------------------------------------------------
318 Edit /etc/avmailgate.conf # Here we say witch user and group
319 # avgate runs under and to use the
320 # sendmail wrapper from qmail that
321 # we install in the next section.
328 # ForwardTo /usr/lib/sendmail -oem -oi
335 ForwardTo /usr/sbin/sendmail -oem -oi
337 --------------------------------------------------------------------------------
338 Edit /etc/avmailgate.acl # We do this to prevent relaying to
339 # other domains than ours.
342 local: hbedv.com antivir.de
346 local: linuxfromsource.org linuxfrombinary.org
348 --------------------------------------------------------------------------------
350 cp bin/avgated /usr/sbin
351 cp bin/avgatefwd /usr/sbin
353 mkdir /var/spool/avmailgate
354 chown daemon.daemon /var/spool/avmailgate
356 chmod 700 /var/spool/avmailgate
357 cd /var/spool/avmailgate
361 chown daemon.daemon *
364 cp hbedv.key /usr/lib/AntiVir/avmgate.key
365 chown daemon.daemon /usr/lib/AntiVir/avmgate.key
367 cp script/antivirupdater /usr/sbin
369 In the fcron section we set the cron job for antivirupdater
371 cp init/rc.avgate /etc/rc.d/init.d/avgate
373 chmod 700 /etc/init.d/avgate
375 Adjust the Sxx and Kxx to your situation
377 cd /etc/rc.d/rc0.d &&
378 ln -s ../init.d/avgate Kxxavgate &&
380 ln -s ../init.d/avgate Sxxavgate &&
382 ln -s ../init.d/avgate Kxxavgate
386 5. Installation of Qmail
387 ========================
389 A. Create a working directory for Qmail and untar sources
390 ---------------------------------------------------------
393 mkdir /opt/qmail/alias &&
395 tar zxvpf qmail-1.03.tar.gz &&
399 B. Change the program parameters. Read the documentation for other
401 ------------------------------------------------------------------
411 Add: (Use your own architecture)
416 C. Create user and group ID's
417 -----------------------------
421 Add: (Use your own ID's if this is conflicting)
428 Add: (Use your own ID's if this is conflicting)
430 alias:x:1000:100::/opt/qmail/alias:
431 qmaild:x:1001:100::/opt/qmail:
432 qmaill:x:1002:100::/opt/qmail:
433 qmailp:x:1003:100::/opt/qmail:
434 qmailq:x:1004:110::/opt/qmail:
435 qmailr:x:1005:110::/opt/qmail:
436 qmails:x:1006:110::/opt/qmail:
441 D. DNS Hack to use DNS response packets larger than 512 bytes
442 Qmail 1.03 chokes on large DNS packets sometimes.
443 -------------------------------------------------------------
449 static union { HEADER hdr; unsigned char buf[PACKETSZ]; } response;
453 static union { HEADER hdr; unsigned char buf[65536]; } response;
456 E. Final compilation and installation
457 -------------------------------------
462 F. Create the init script.
463 --------------------------
465 cat << EOF > /etc/init.d/qmail
468 # Begin $rc_base/init.d/qmail
470 # Based on sysklogd script from LFS-3.1 and earlier.
471 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
473 source /etc/sysconfig/rc
476 test -x /opt/qmail/rc || exit 0
480 echo -n "Starting Qmail... "
481 sh -cf '/opt/qmail/rc &'
486 echo -n "Stopping Qmail... "
487 killall -9 qmail-send
492 echo -n "Restarting Qmail... "
493 killall -HUP qmail-lspawn
494 killall -ALRM qmail-lspawn
499 echo "Usage: $0 {start|stop|restart}"
506 # End /etc/rc.d/init.d/qmail
510 G. Set up links and permissions
511 -------------------------------
513 chmod 700 /etc/init.d/qmail
515 Adjust the Sxx and Kxx to your situation
517 cd /etc/rc.d/rc0.d &&
518 ln -s ../init.d/qmail Kxxqmail &&
520 ln -s ../init.d/qmail Sxxqmail &&
522 ln -s ../init.d/qmail Kxxqmail
525 ln -s /opt/qmail/bin/sendmail
531 Configuration of qmail can happen in many ways, read the documentation
532 on the different kinds of configurations. At the end of this document I
533 go into initialization and configuration of qmail.
537 6. Installation of Nail
538 ============================
540 This peace of software is used by internal processes such as
543 ./configure --prefix=/usr \
544 --with-mailspool=/var/mail \
545 --with-sendmail=/usr/sbin/sendmail &&
549 ln -s /usr/bin/nail mail &&
550 ln -s /usr/bin/nail mailx
554 7. Installation of fcron
555 ========================
557 Fcron is the program we use as scheduler for some virus update scripts.
558 Its a very handy program anyway so here we go.
560 A. Setting up a fcron user and group.
561 -------------------------------------
564 fcron:x:14:14::/dev/null:/bin/false
573 ./configure --prefix=/usr \
574 --with-username=fcron \
575 --with-sendmail=/usr/sbin/sendmail \
576 --with-groupname=fcron
579 C. Add Optimization for you system.
580 -----------------------------------
585 > OPTIM = -O3 -march=i686 -Wall
588 D. Make and install fcron.
589 --------------------------
596 ln -s fcrontab crontab
598 E. Add init script to /etc/rc.d/init.d
599 --------------------------------------
601 cat > /etc/rc.d/init.d/fcron << "EOF"
603 # Begin $rc_base/init.d/fcron
604 # Based on sysklogd script from LFS-3.1 and earlier.
605 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
606 source /etc/sysconfig/rc
610 echo "Starting fcron..."
614 echo "Stopping fcron..."
626 echo "Usage: $0 {start|stop|restart|status}"
630 # End $rc_base/init.d/fcron
633 F. Set up links and permissions
634 -------------------------------
636 chmod 700 /etc/rc.d/init.d/fcron
638 Adjust the Sxx and Kxx to your situation.
640 cd /etc/rc.d/rc0.d &&
641 ln -s ../init.d/fcron Kxxfcron &&
643 ln -s ../init.d/fcron Sxxfcron &&
645 ln -s ../init.d/fcron Kxxfcron
647 use this to start fron
649 /etc/init.d/fcron start
651 So if we want to make use of the scheduler do this
655 We add the entries we need when appropriate programs are installed.
659 25 0 * * * root /usr/sbin/antivirupdater -q
663 27 4,16 * * * /usr/f-prot/check-updates.sh -cron
667 8. Installation of Procmail.
668 ============================
670 We use procmail to filter the delivery of mail to /usr/cyrus/bin/deliver that
671 delivers the mail to the IMAP folders. It will not make use of any mail{box,dir}
674 cd /path/to/procmail-3.22/src
675 make BASENAME=/usr install
679 9. Installation of SpamAssassin.
680 ================================
683 http://spamassassin.taint.org/dist/INSTALL
685 There are some perl-modules that not come with the presumed perl-5.8.0 standard
686 installation in LFS 4.0 or perl-5.8.0 in general.
688 SpamAssassin Razor Cyrus and probably more depends on perl, no worries there is
689 an easy way to update your system.
692 When you are connected to the internet commence this as root:
696 A series of questions is asked and stores this information in:
697 /usr/lib/perl5/5.8.0/CPAN/Config.pm
699 if you get weird looping experiences say /usr/bin/wget --passive in
702 Now type this in the CPAN shell:
704 o conf prerequisites_policy ask
707 And now for ease of administration, install these optional perl modules .
710 install Term::ReadKey
713 install Term::Readline
715 i /Term::Readline::GNU/
716 install Term::Readline::GNU
718 i /Term::Readline::Perl/
719 install Term::Readline::Perl
721 What follows are dependences of SpamAssassin although it doesn't need it.
730 install Mail::Internet
735 SpamAssassin make a lot use of them if you do install them.
739 i /Mail::SpamAssassin/
740 install Mail::SpamAssassin
745 Once the modules are installed you can read all about it by doing:
747 perldoc <name>::<name>
754 Oke now the local source tarball method.
756 Untar the SpamAssassin archive and say:
762 If you want to prevent spam checking from eg. user@domain.com you
765 Edit /etc/mail/spamassassin/local.cf
769 whitelist_from user@domain.com
773 10. Installation of Razor-agents.
774 =================================
776 http://razor.sourceforge.net/docs/install.html
778 Untar the razor-agents archive and say:
786 11. Installation of Razor-agents-sdk.
787 =====================================
789 Oke Razor will work fine without them, so this is optional.
797 12. Installation of F-Prot Antivirus.
798 =====================================
802 tar zxvf /path/to/fp-linux_3.12b.tar.gz
803 mv fp-linux_3.12b f-prot
805 ln -fs /usr/f-prot/f-prot.sh bin/f-prot
806 ln -fs /usr/f-prot/man8/f-prot.8 man/man8/
807 ln -fs /usr/f-prot/man8/check-updates.sh.8 man/man8/
809 chmod +x /usr/f-prot/f-prot*
810 chmod +x /usr/f-prot/check*
812 ln -fs /usr/f-prot/man8/f-prot.8 man/man8/
813 ln -fs /usr/f-prot/man8/check-updates.sh.8 man/man8/
815 For more information see this:
817 /usr/bin/f-prot -help
821 13. Installation of Distributed Checksum Clearinghouse.
822 =======================================================
829 Now to see if it all works do:
835 14. Installation of Anomy-sanitizer.
836 ===================================
838 Anomy-sanitizer uses this perl library's, but they are already
839 installed with a standard perl install.
845 Untar the packet in /usr/src
850 mkdir /var/quarantine
852 This whole section is used from the mail.txt hint.
853 Its a good config so why not use it ?
856 cat > /usr/anomy/anomy.conf << "EOF"
857 # Configuration file for Anomy Sanitizer
860 # Do not log to STDERR:
863 # Don't insert log in the message itself:
866 # Advertisement to insert in each mail header:
867 header_info = X-Sanitizer: This mail was sanitized
871 # Enable filename based policy decisions:
874 # Protect against buffer overflows and null values:
877 # Replace MIME boundaries with our own:
880 # Fix invalid and ambiguous MIME boundaries, if possible:
883 # Trust signed and/or encrypted messages:
885 msg_pgp_warning = WARNING: Unsanitized content follows.\n
887 # Defang shell scripts:
890 # Defang active HTML:
893 # Defang UUEncoded files:
896 # Sanitize forwarded content too:
899 # Testing? Set to 1 for testing, 0 for production:
902 ## Warn user about UN scanned parts, etc.
905 # Force all parts (except text/html parts) to
912 # Disable "score" based mail discarding:
916 msg_file_drop = \n*****\n
917 msg_file_drop += NOTE: An attachment named %FILENAME was deleted from
918 msg_file_drop += this message because was a windows executable.
919 msg_file_drop += Contact the system administrator for more information.
922 ## File attachment name mangling rules:
925 file_name_tpl = /var/quarantine/att-$F-$T.$$
927 # Number of rulesets we are defining:
929 file_default_policy = defang
931 # Delete probably nasty attachments:
932 file_list_1 = (?i)(winmail.dat)|
933 file_list_1 += (\.(vb[se]|exe|com|cab|dll|ocx|msi|cmd|bat|pif|lnk|hlp|ms[ip]|reg|asd))$
934 file_list_1_policy = drop
935 file_list_1_scanner = 0
937 # Allow known "safe" file types and those that can be
938 # scanned by the downstream virus scanner:
939 file_list_2 = (?i)\.(doc|dot|rtf|xls|ppt|xlw|jpg|gif|png|tiff?|txt|zip|tgz|gz)
940 file_list_2_policy = accept
941 file_list_2_scanner = 0
943 # Any attachment not listed above gets renamed.
948 13. Installation of Imap.
949 ========================
951 Do some unpacking, by now you should know ;)
953 A. Compile and install SASL
954 ---------------------------
956 ./configure --prefix=/usr --disable-krb4 \
962 B. Create uid/gid for the cyrus admin
963 -------------------------------------
967 We assume a user of "cyrus" and a group of "mail",
968 though any user and group name can be used.
972 Add: (Use your own ID's if this is conflicting)
974 cyrus:x:90:90:Imap-Server:/usr/cyrus:/bin/bash
978 Add: (Use your own ID's if this is conflicting)
987 C. Find a missing header.
988 -------------------------
990 First find com_err.h and link it to /usr/include/com_err.h
991 or if you don't have it get it here:
993 http://www.ludd.luth.se/~jnilsson/cvsweb/cvsweb.cgi/src/contrib/com_err
997 On a LFS-4 system its located @ /usr/include/et/com_err.h
1000 ln -s et/com_err.h .
1003 D. Compile and install IMAP
1004 ---------------------------
1006 ./configure --prefix=/usr \
1009 --with-cyrus-user=cyrus \
1010 --with-cyrus-group=mail &&
1015 And install some tools
1017 cp -av tools/ /usr/cyrus &&
1018 rm -r /usr/tools/CVS &&
1019 chown -R cyrus.mail /usr/cyrus
1026 The last 3 lines are only necessary if you use SSL
1027 Edit /etc/imapd.conf
1029 configdirectory: /var/imap
1030 partition-default: /var/spool/imap
1032 srvtab: /var/imap/srvtab
1033 allowanonymouslogin: no
1034 tls_ca_file: /var/imap/server.pem
1035 tls_cert_file: /var/imap/server.pem
1036 tls_key_file: /var/imap/server.pem
1039 F. Making the director's
1040 ------------------------
1042 touch /var/adm/imapd.log
1043 mkdir /var/imap /var/spool/imap /var/imap/srvtab
1044 chown cyrus /var/imap /var/spool/imap /var/imap/srvtab
1045 chgrp mail /var/imap /var/spool/imap /var/imap/srvtab
1046 chmod 750 /var/spool/imap /var/imap/srvtab
1049 G. Making the imap structure
1050 ----------------------------
1055 chattr +S . user quota user/* quota/*
1056 chattr +S /var/spool/imap
1059 touch /var/spool/mqueue
1060 chattr +S /var/spool/mqueue
1063 H. Change Other files
1064 ---------------------
1066 Added to /etc/services although only imap/imaps is needed.
1068 imap 143/tcp # remove old imap2 !
1079 Add to: /etc/syslog.conf
1081 local6.debug -/var/log/imapd.log
1082 auth.debug -/var/log/auth.log
1084 And restart the syslog daemon:
1086 /etc/init.d/sysklogd restart
1089 I. Setting the cyrus user password for imap
1090 -------------------------------------------
1092 /usr/sbin/saslpasswd2 cyrus
1094 chown cyrus.mail /etc/sasldb2
1096 cd /usr/src/cyrus-imapd-2.1.9
1098 You can uncomment the things you don't like here
1100 cp master/conf/normal.conf /etc/cyrus.conf
1103 J. Getting SSL to work.
1104 -----------------------
1105 We already adapted the /etc/imapd.conf for SSL
1106 Its known that M$ Outlook and Netscape mail clients
1107 can handle SSL connections.
1111 openssl req -new -x509 -nodes -out /var/imap/server.pem -keyout \
1112 /var/imap/server.pem -days 365 &&
1113 chown cyrus.mail /var/imap/server.pem
1116 K. Making the init.d script.
1117 ----------------------------
1119 cat > /etc/rc.d/init.d/imapd << "EOF"
1121 # Begin $rc_base/init.d/imapd
1123 # Based on sysklogd script from LFS-3.1 and earlier.
1124 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
1126 source /etc/sysconfig/rc
1127 source $rc_functions
1131 echo "Starting the IMAP server..."
1132 /usr/cyrus/bin/master &
1137 echo "Stopping the IMAP server..."
1138 killproc /usr/cyrus/bin/master
1142 echo "Reloading the IMAP server..."
1143 reloadproc /usr/cyrus/bin/master
1153 statusproc /usr/cyrus/bin/master
1157 echo "Usage: $0 {start|stop|reload|restart|status}"
1163 # End $rc_base/init.d/imapd
1166 Adjust the runlevel link numbers Kxx and Sxx to taste.
1168 chmod 700 /etc/rc.d/init.d/imapd &&
1169 cd /etc/rc.d/rc0.d &&
1170 ln -s ../init.d/imapd Kxximapd &&
1172 ln -s ../init.d/imapd Sxximapd &&
1174 ln -s ../init.d/imapd Kxximapd
1177 /etc/init.d/imapd start
1180 Well, if it works, you supposed to see this:
1183 Active Internet connections (servers and established)
1184 Proto Recv-Q Send-Q Local Address Foreign Address State
1185 tcp 0 0 *:imaps *:* LISTEN
1186 tcp 0 0 *:pop3s *:* LISTEN
1187 tcp 0 0 *:pop3 *:* LISTEN
1188 tcp 0 0 *:imap *:* LISTEN
1189 tcp 0 0 *:sieve *:* LISTEN
1191 You might only need imap or imaps , adjust this in /etc/cyrus.conf
1192 Comment out services that you don't want.
1194 L. Check configuration
1195 ----------------------
1197 Now lets see what works and what not.
1199 If you want to login with telnet to test you need to add:
1207 telnet localhost imap
1209 Test all the authentications possible and again fiddling with the
1210 /etc/imapd.conf wont hurt. Read the imapd.conf man page and just change the
1211 the config file, restart the daemon and:
1213 tail -f /var/log/imapd.log
1214 tail -f /var/log/sys.log
1215 tail -f /var/log/auth.log
1217 Now become the cyrus admin and test the various options.
1221 imtest -m login -p imap localhost
1222 imtest -m OTP -p imap localhost
1223 imtest -m DIGEST-MD5 -p imap localhost
1224 imtest -m CRAM-MD5 -p imap localhost
1226 Use this to bail out !!
1229 You can test STARTTLS by using imtest:
1231 imtest -t "" localhost
1234 M. Per User Imap Configuration
1235 ------------------------------
1237 This is the bare minimum to perform for each imap user you want to add.
1239 First become the cyrus administrator
1243 Use the cyradm program to administor the IMAP folders for each user.
1245 cyradm --auth login localhost
1247 localhost.localnet> cm user.john
1248 localhost.localnet> cm user.john.SPAM
1249 localhost.localnet> quit
1255 And set the imap password for john
1260 There are more things possible, but knowing to delete a mailbox is handy
1261 if you new to all this.
1263 Say to the access control list of the user john mailbox that the
1264 cyrus user may delete john's folders, this is not the default case.
1266 localhost.localnet> setaclmailbox user.john cyrus c
1268 localhost.localnet> deletemailbox user.john
1270 If you want to get into it do this:
1272 localhost.localnet> help
1275 authenticate, login, auth authenticate to server
1276 chdir, cd change current directory
1277 createmailbox, create, cm create mailbox
1278 deleteaclmailbox, deleteacl, dam remove ACLs from mailbox
1279 deletemailbox, delete, dm delete mailbox
1280 disconnect, disc disconnect from current server
1281 exit, quit exit cyradm
1282 help, ? show commands
1283 info display mailbox/server metadata
1284 listacl, lam, listaclmailbox list ACLs on mailbox
1285 listmailbox, lm list mailboxes
1286 listquota, lq list quotas on specified root
1287 listquotaroot, lqr, lqm show quota roots and quotas for mailbox
1288 reconstruct reconstruct mailbox (if supported
1289 renamemailbox, rename, renm rename (and optionally relocate) mailbox
1290 server, servername, connect show current server or connect to server
1291 setaclmailbox, sam, setacl set ACLs on mailbox
1292 setinfo set server metadata
1293 setquota, sq set quota on mailbox or resource
1294 version, ver display version info of current server
1298 14. Configuration of Qmail and Mailboxes.
1299 =========================================
1301 A. First make sure all mail users have valid unix accounts.
1302 -----------------------------------------------------------
1304 Users will not require a password set. So they become
1305 valid unix accounts without unix login.
1306 John is an admin because root is not supposed to get mail.
1311 john:x:501:500:John the ripper:/home/john:/bin/bash
1312 susie:x:502:500:Susie Summer:/home/susie:/bin/bash
1313 dirk:x:503:500:Dirk Beekmans:/home/dirk:/bin/bash
1314 olaf:x:504:500:Olaf Olsen:/home/olaf:/bin/bash
1315 jennifer:x:505:500:Jennifer Loopneus:/home/jennifer:/bin/bash
1316 pamela:x:506:500:Pamela Andersom:/home/pamela:/bin/bash/bash
1320 mailuser:x:500:john,susie,dirk,olaf,jennifer,pamela
1324 mkdir john susie dirk olaf jennifer pamela
1326 chown -R <user>.mailuser <userdir>/ (for all users)
1328 You repeat the above line if you finished or do it as last
1330 B. Create a master user ID and home directory for the new domain
1331 ----------------------------------------------------------------
1333 This is roughly how stuff works.
1334 Mail is coming in for a domain, lets say pamela@linuxfrombinary.org.
1335 It's first put into a drop box /home/binary/Maildir/ and then processed
1336 further via .qmail-xxx files. These files contain a user name who is supposed
1337 to get the mail. The user has a .qmail file in his or her home directory
1338 which says what to do with the incoming mail. In this case pipe it to
1339 the program /usr/bin/procmail that filters the mail and send that to the
1340 /usr/cyrus/bin/deliver program which stores it in the IMAP boxes.
1348 source:x:507:500:Mail account for linuxfromsource.org:/home/source:/bin/bash
1349 binary:x:508:500:Mail account for linuxfrombinary.org:/home/binary:/bin/bash
1353 mailuser:x:500:john,susie,dirk,olaf,jennifer,pamela,source,binary
1356 chown -R source.mailuser source/
1357 chown -R binary.mailuser binary/
1360 C. Editing the Qmail Control/Config files
1361 -----------------------------------------
1363 Editing the control files is tricky and I've spent lot's of time
1364 fiddling around with it. Key thing to understand is that
1365 the host and domainname have something to do with the canonicalized
1366 name that is assigned to your link with the internet.
1367 For the people that use a ppp or an adsl connection this is often
1368 something like sdf23-2.dsl.blabla.com Please don't ask me why,
1369 it works and if anyone has a good explanation mail me !!
1371 One way of finding out is with the commands that come with bind
1372 dig or nslookup you can also try to login on an other box, logout,
1373 and than run to that other box login again and read: your last login
1374 was on xxx.xxxx.xxxxx.org or do an chat session on that box. I know
1375 it isn't elegant but it works ;-)
1377 For now lets hack some qmail
1380 --------------------------------------------------------------------------------
1381 cat << EOF > /opt/qmail/rc
1384 # Using splogger to send the log through syslog.
1385 # Using qmail-local to deliver messages to Maildir by default.
1387 exec env - PATH="/opt/qmail/bin:$PATH" \
1388 qmail-start ./Maildir/ splogger qmail &
1390 --------------------------------------------------------------------------------
1392 chmod 700 /opt/qmail/rc
1394 cd /opt/qmail/control
1396 --------------------------------------------------------------------------------
1398 Edit: me # This is the hostname of local server
1402 <hostname> (example adsl32.net.xs4all.nl)
1404 --------------------------------------------------------------------------------
1406 Edit: virtualdomains # Specify virtual domains
1410 linuxfromsource.org:source
1411 linuxfrombinary.org:binary
1413 --------------------------------------------------------------------------------
1415 Edit: locals # Domains that should be treated as
1420 localhost # The local name
1421 adsl32.net.xs4all.nl # The canonicalized name
1422 intern.net # An example local domain
1424 --------------------------------------------------------------------------------
1426 Edit: defaultdomain # Same as 'me' minus the first part
1430 <domainname> (example net.xs4all.nl)
1432 --------------------------------------------------------------------------------
1434 Edit: smtpgreeting # Adjust to taste
1438 Hi and welcome to this SMTP server
1440 --------------------------------------------------------------------------------
1442 Edit: rcpthosts # Important file to prevent relaying of
1443 mail by outsiders, List all machines
1444 and domains on the network that
1445 allowed to relay mail on this server.
1451 otherinterndomain.org
1458 Make the aliases, John is a mortal user on the system who gets
1459 administrative email eg for root and for bounced or failed messages.
1460 The first three aliases are necessary. For each user an alias is a necessity.
1461 and only needs the username
1465 echo john > .qmail-mailer-daemon
1466 echo john > .qmail-postmaster
1467 echo john > .qmail-root
1469 and further for all users:
1471 echo <user> > .qmail-<user>
1475 echo john > .qmail-john
1478 D. Per user virtual domain config
1479 --------------------------------
1481 Now we split up our users for the virtual domains. If new mail arrives it is
1482 forwarded to the user in the first part of the email address. Lets say there
1483 is mail for susie@linuxfromsource.org. The alias file .qmail-susie is used to
1484 forward the mail to susie, '&user' means forward. The .qmail file in her home
1485 directory now determine the faith of the message.
1487 The file .qmail-default is used if all other usernames fails to have a
1488 .qmail-<user> alias for it. For example 'zuzie@linuxfromsource.org'.
1489 You can write one line that says: ./Maildir/ to .qmail-default.
1490 Now unresolved mail is sitting in the /home/virt-dom/Maildir/new directory.
1492 John is the local mail admin who loves to get the unresolved mail and therefore
1493 we say &john to '.qmail-default'. Now John determine the faith of the message.
1494 He either trash it of forward it to the appropriate recipient.
1499 /opt/qmail/bin/maildirmake Maildir
1500 echo '&john' > .qmail-default
1501 echo '&john' > .qmail-postmaster
1502 echo '&john' > .qmail-webmaster
1503 echo '&john' > .qmail-root
1504 echo '&john' > .qmail-john
1505 echo '&susie' > .qmail-susie
1506 echo '&dirk' > .qmail-dirk
1507 chown -R source.mailuser .
1512 /opt/qmail/bin/maildirmake Maildir
1513 echo '&john' > .qmail-default
1514 echo '&john' > .qmail-postmaster
1515 echo '&john' > .qmail-webmaster
1516 echo '&john' > .qmail-root
1517 echo '&olaf' > .qmail-olaf
1518 echo '&jennifer' > .qmail-jennifer
1519 echo '&pamela' > .qmail-pamela
1520 chown -R binary.mailuser .
1524 And now for all users substitute <user> for the login name. Here comes the
1525 filtering with procmail into play.
1529 echo '| preline /usr/bin/procmail' > .qmail
1531 Now make sure the permissions are set right.
1533 chown -R <user>.mailuser <userdir>/ (for all users)
1537 16. Configuration of Procmail.
1538 ==============================
1540 Here you find a example configuration file, adjust to taste
1541 This goes to each users home directory, change the <user>
1542 with the real user name eg. john
1544 touch /var/log/procmail.log
1545 chmod 666 /var/log/procmail.log
1547 chmod 600 /home/<user>/.procmailrc
1549 cat > .procmailrc << "EOF"
1551 PATH=/usr/bin:/bin:/usr/cyrus/bin:/usr/anomy/bin
1553 #VERBOSE=1 # uncomment these if you want to see
1554 #LOGABSTRACT=all # more what's happening in procmail.log
1555 LOGFILE="/var/log/procmail.log"
1556 SANE="deliver -a $USER -m user.$USER"
1560 #######################################################
1561 # FIRST: REMOVE THE LEADING "From " field #
1562 # Cyrus bombs if it sees a leading "From " (not #
1563 # to be confused with "From:"). By running sed #
1564 # as a filter we simply remove the first line without #
1565 # any real thought. #
1566 #######################################################
1571 # Anomy mail sanitizer
1574 | sanitizer.pl /usr/anomy/anomy.conf
1583 * ^X-Spam-Status: Yes
1587 # Empty To: From: Subject:
1602 # Porn Spam although you might wand to see those ;-)
1605 * ^Subject.*(\|<\pornography\>)
1609 * ^.*(\|<\pornography\>)
1613 # Example From spam traps although SpamAssassin should filter it.
1620 * ^From:.*(advertising|sales|offers|promotion|reply|request|theuseful)
1624 # Example Subject spam traps
1627 * ^Subject:.*\[ADV\]
1649 16. Starting up all processes
1650 =============================
1652 You should know how to make the links for the different run levels.
1653 Otherwise Gerard Beekmans has a guide where this issue is addressed.
1655 /etc/init.d/sysklogd restart
1656 /etc/init.d/avgate start
1657 /etc/init.d/qmail start
1658 /etc/init.d/imap start
1662 17. Monitoring the processes.
1663 =============================
1665 Oke just start mailing everyone from localhost and remote and
1666 have a terminal running with the following command:
1668 tail -f /var/log/mail.log
1670 tail -f /var/log/sys.log
1672 tail -f /var/adm/imapd.log
1674 tail -f /var/log/procmail.log
1677 Active Internet connections (servers and established)
1678 Proto Recv-Q Send-Q Local Address Foreign Address State
1679 tcp 0 0 *:pop3 *:* LISTEN
1680 tcp 0 0 *:imap *:* LISTEN
1681 tcp 0 0 *:ssh *:* LISTEN
1682 tcp 0 0 *:smtp *:* LISTEN
1683 Active UNIX domain sockets (servers and established)
1684 Proto RefCnt Flags Type State I-Node Path
1685 unix 2 [ ACC ] STREAM LISTENING 16068 /var/imap/socket/lmtp
1688 If you wanna know WTF Qmail is doing:
1690 for reading the queue:
1691 /opt/qmail/bin/qmail-qread
1694 /opt/qmail/bin/qmail-qstat
1697 /opt/qmail/bin/qmail-showctl
1701 18. Migrating mail from backups.
1702 ================================
1704 Make a back up of the /var/spool/imap/user directory
1705 and the /var/imap/mailboxes.db on your existing mail server.
1708 tar cvpf user-backup.tar user/
1709 mv user-backup.tar ../../imap
1711 Add to the backup /var/imap/mailboxes.db
1714 tar uvpf user-backup.tar mailboxes.db
1716 gzip -9 user-backup.tar
1719 Go to the new system and unpack the user folders and mailboxes.db
1721 mv user-backup.tar.gz /var/spool/imap
1723 tar zxvpf user-backup.tar.gz
1724 mv mailboxes.db ../../imap/
1726 Now that all the old mailboxes are restored, we can rebuild the mailboxes.db.
1728 su - cyrus # Become the cyrus user.
1730 ctl_cyrusdb -r # rebuild the cyrus mailboxes database
1731 reconstruct # reconstruct mailboxes
1733 cyradm --auth login localhost # Use the admin console for cyrus-imap.
1734 Password: # Enter the imap/sasl password.
1735 localhost.localnet> lm # Check to see if mailboxes are restored.
1736 localhost.localnet> exit # Leave the cyrusadm console.
1738 exit # exit the cyrus user.
1740 Every user that has imap login access needs a entry in /etc/sasldb2 again
1741 So do this for every imap user on the new server.
1747 If you want a hint on reading a remote imap box with fetchmail on a client,
1748 compile fetchmail and procmail and put the following in a .fetchmailrc in your
1754 poll "linuxfromsource.org"
1760 mda "/usr/bin/procmail -d john"
1766 poll mail.linuxfromsource.org port 993
1776 poll mail.linuxfrombinary.org with proto imap:
1777 plugin "ssh %h /usr/cyrus/bin/imtest" auth ssh;
1778 user john is john here
1782 19. Interesting readings.
1783 =========================
1785 All this information didn't come to me in a dream. It's a combination of
1786 sources that I used. A little file that I used to log thing has grown into
1787 this hint and hopefully it's usefull for others as well. Understanding e-mail
1788 by this hint is not gonna help you enough, you have to RTFM A LOT.
1792 http://linuxdoc.org/HOWTO/Cyrus-IMAP.html
1794 Source documentation:
1795 file://localhost/usr/src/cyrus-imapd-2.0.16/doc/index.html
1798 http://www.linuxjournal.com/article.php?sid=2313
1799 http://www.linuxworld.com/site-stories/2002/0410.ldap4.html
1800 http://www.abiglime.com/webmaster/articles/cgi/062398.htm
1801 http://www.summersault.com/chris/techno/qmail/qmail-antispam.html
1802 http://sysadmin.oreilly.com/news/imap2_1000.html
1805 http://www.openantivirus.org/projects.php
1806 http://docsrv.caldera.com:8457/en/volutionmsg_ag/msgag.mailadmin.html
1808 Google, Some ppl on #lfs, a friend enz
1810 Running Qmail - ISBN 0-672-31945-4 - Richard Blum - Sams Publishing 2000
1817 The author does not feel responsible for loss or destruction of data and
1818 mail due to typos and bad language. So if you wipe out you system or get your
1819 dog killed don't come to me to cry on my shoulder. Be a man/woman and take
1820 responsibility for your own actions. On the other hand if your are successful
1821 and want to contribute, throw a BIG bag of money to Gerard Beekmans, he deserves
1822 it. This is my contribution to LFS and improvements are welcome.