Building A Reliable Open Source Mail Server
|
This tutorial is one of many
available on the Internet. The focus here is on ease of implementation,
avoidance of heavy customization (compiling from source, long config
files), and software manageability (all RPM based).
Benefits
o no licenses
o open source GNU software
o secure online interface using SSL
o minimal hardware requirements
o server side Spam filtering
Bundled Distribution
Software Requirements
o Fedora Core 1 with the following packages:
o Apache
o PHP
o Postfix
o wget
o Squirrelmail
Unbundled Software
Requirements
o Apt 0.5.15 (http://www.freshrpms.net)
o Courier IMAP 2.2.1 (http://www.courier-mta.org)
o Maildrop 1.6.3 (http://www.courier-mta.org)
o SpamAssassin 2.63-1 (http://www.spamassassin.org)
o perl-Mail-Spamassassin 2.63-1 (http://www.spamassassin.org
o Anomy Mail Tools 1.66 (http://mailtools.anomy.net/)
o Subjadd (http://www.firstpr.com.au/web-mail)
o Squirrelmail 1.4.2-1 (http://www.squirrelmail.org)
Remove if already installed
o IMAP
o SpamAssassin
o perl-Mail-Spamassassin
Software Not Used
o LDAP
o MySQL, PostgreSQL
Account Management and
Mailboxes
o standard user accounts via the /etc/passwd and /etc/shadow files
Examples used in this
tutorial need to be replaced with the relevant
values
o example.com
o 192.168.1.1
|
|
I. Download and Install the APT Package Manager for RPM from http://www.freshrpms.net.
This package manager ensures easy installation of any needed software and is much faster than up2date/Fedora mirrors.
|
$ su - # wget http://ftp.freshrpms.net/pub/freshrpms/fedora/linux/1/apt/apt-devel-0.5.15cnc3-0.1.fr.i386.rpm # wget http://ftp.freshrpms.net/pub/freshrpms/fedora/linux/1/apt/apt-0.5.15cnc3-0.1.fr.i386.rpm # rpm -ivh apt*
|
The postgres, mysql, and openldap packages are only needed to satisfy Courier Imap spec files. These packages will not be needed or installed.
|
# apt-get update # apt-get install postgresql-devel # apt-get install mysql-devel # apt-get install openldap-servers # apt-get install perl-Digest-SHA1 # exit
|
II. Build the RPM Development Directory Structure for Courier Imap and Maildrop
The Courier Imap and Maildrop packages come bundled with preconfigured spec files. They can be built as a regular user straight from the source zip files.
|
$ mkdir rpmbuild $ cd rpmbuild $ mkdir BUILD RPMS SOURCES SPECS SRPMS $ cd RPMS $ mkdir i386 i586 i686 $ cd ../SRPMS $ mkdir i386 i586 i686 $ cd $HOME $ vi .rpmmacros %_topdir %(echo $HOME)/rpmbuild %debug_package %{nil}
|
III. Build the Courier IMAP and Maildrop RPM Packages
|
$ cd $HOME $ wget http://unc.dl.sourceforge.net/sourceforge/courier/courier-2.2.1.tar.bz2 $ wget http://unc.dl.sourceforge.net/sourceforge/courier/maildrop-1.6.3.tar.bz2 $ rpmbuild -ta courier-imap-2.2.1.tar.bz2 $ rpmbuild -ta maildrop-1.6.3.tar.bz2 $ cd rpmbuild/RPMS/i386 $ su Password:
|
IV. Install and Enable the Courier IMAP and Maildrop Services
|
# rpm -ivh courier-imap-2.2.1-1.1.i386.rpm maildrop-* # chkconfig --add courier-imap # chkconfig courier-imap on # service courier-imap start
|
V. Configure Postfix and Integrate it with Postfix
This is a very basic configuration for Postfix to get it running and configured to integrate with Maildrop. The parameters listed are the ONLY ones that need to be changed.
|
# vi /etc/postfix/main.cf myhostname = example.com mydomain = example.com myorigin = $mydomain inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, $mydomain mailbox_command = /usr/bin/maildrop -d "$USER" -f "$SENDER" "$EXTENSION"
# cp /etc/aliases /etc/postfix/aliases # chkconfig postfix on # service postfix start # exit $
|
VI. Download and Install SpamAssassin
|
$ cd $HOME/rpmbuilds/RPMS/i386 $ wget http://eu.spamassassin.org/released/RPMs/perl-Mail-SpamAssassin-2.63-1.i386.rpm $ wget http://eu.spamassassin.org/released/RPMs/spamassassin-2.63-1.i386.rpm $ wget http://eu.spamassassin.org/released/RPMs/spamassassin-tools-2.63-1.i386.rpm $ su # rpm -ivh perl-Mail* # rpm -ivh spamassassin* # chkconfig spamassassin on # service spamassassin start
|
VII. Integrate Maildrop with SpamAssassin
|
# vi /etc/maildroprc import SENDER import RECIPIENT SENDMAIL=/usr/sbin/sendmail DEFAULT="./Maildir" xfilter "/usr/bin/spamc -f" # exit
|
Setup a regular user to receive email. The maildirmake command is part of the Maildrop package. It creates Qmail style mailboxes which are traditionally faster than standard Unix mbox formats.
|
# su - darren $ maildirmake Maildir $ maildirmake -f Spam Maildir $ vi $HOME/.mailfilter if ( /^X-Spam-Status: Yes/ ) { cc "!uce@ftc.gov" to "Maildir/.Spam" } $ chmod 600 $HOME/.mailfilter
|
VIII. Integrate SpamAssassin with Anomy Mail Tools
Modify the "Unicode UTF-8" locales in /etc/sysconfig/i18n. There have been numerous issues with Anomy, Perl, and formatting as a result. See http://www.linuxmanagers.org/pipermail/linuxmanagers/2002-December/000885.html for more details.
|
# vi /etc/sysconfig/i18n LANG="en_US" SUPPORTED="en_US:en" SYSFONT="lat0-sun16" SYSFONTACM="iso01"
|
Download Anomy Mail Tools
|
# cd /usr/local # wget http://mailtools.anomy.net/dist/anomy-sanitizer-1.66.tar.gz # gunzip anomy* # tar xvf anomy* # vi /etc/maildroprc import SENDER import RECIPIENT SENDMAIL=/usr/sbin/sendmail DEFAULT="./Maildir" xfilter "/usr/bin/spamc -f" ANOMY=/usr/local/anomy/ xfilter "/usr/local/anomy/bin/sanitizer.pl /usr/local/anomy/anomy.conf 2>>~/mailfilter-log.txt | cat" # cd /usr/local/anomy # wget http://www.ufsdump.org/scripts/anomy.conf
|
Download the "subjadd" Utility
|
# cd /usr/local/anomy/bin # wget http://www.ufsdump.org/downloads/subjadd.gz # gunzip subjadd.gz # su - darren $ vi .mailfilter if ( /^X-Spam-Status: Yes/ ) { cc "!uce@ftc.gov" to "Maildir/.spam" } if ( /^*** Attached file dropped ***/:b ) { cc "Maildir/.Virus" xfilter "/usr/local/anomy/bin/subjadd [Virus-Detected]" to "Maildir" } $ maildirmake -f Virus Maildir
|
IX. Install and configure Squirrelmail for Courier IMAP
|
$ cd $HOME/rpmbuild/RPMS/i386 $ wget http://easynews.dl.sourceforge.net/sourceforge/squirrelmail/squirrelmail-1.4.2-1.noarch.rpm $ su # rpm -Uvh squirrlemail*
# cd /usr/share/squirrelmail/conf # ./conf.pl
<<snip>
D. Set pre-defined settings for specific IMAP servers
Command >> D SquirrelMail Configuration : Read: config.php
<<snip>>
Please select your IMAP server: cyrus = Cyrus IMAP server uw = University of Washington's IMAP server exchange = Microsoft Exchange IMAP server courier = Courier IMAP server macosx = Mac OS X Mailserver quit = Do not change anything Command >> courier
imap_server_type = courier default_folder_prefix = INBOX. trash_folder = Trash sent_folder = Sent draft_folder = Drafts show_prefix_option = false default_sub_of_inbox = false show_contain_subfolders_option = false optional_delimiter = . delete_folder = true
Press any key to continue...
<<snip>>
Command >> S
Data saved in config.php Press enter to continue...
<<snip>>
Command >> q
|
X. Configure Apache
This is a very basic configuration of an Apache webserver using "name based" virtual hosting. These variables are the ONLY ones that need to be changed.
|
# vi /etc/httpd/conf/httpd.conf ServerAdmin webmaster@example.com ServerName 192.168.1.1:80 NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@example.com DocumentRoot /var/www/html/example ServerName example.com ServerAlias www.example.com ErrorLog logs/error_log CustomLog logs/access_log common </VirtualHost>
# mkdir /var/www/html/example # mkdir /var/www/html/example/logs # touch /var/www/html/example/logs/access_log # touch /var/www/html/example/logs/error_log # chown -R apache:apache /var/www/html/example/logs/
|
|
XII. Debug Messages
An approrpiately delivered message should log this entry:
|
# tail -f /var/log/maillog Mar 17 21:44:09 asaph postfix/smtpd[30781]: connect from gateway4.stpt.com[216.34.200.41] Mar 17 21:44:10 asaph postfix/smtpd[30781]: 600E33A7F3: client=gateway4.stpt.com[216.34.200.41] Mar 17 21:44:10 asaph postfix/cleanup[30783]: 600E33A7F3: message-id=<2050.67.154.138.34.1079588774 .squirrel@216.34.200.29> Mar 17 21:44:10 asaph postfix/smtpd[30781]: disconnect from gateway4.stpt.com[216.34.200.41] Mar 17 21:44:10 asaph postfix/nqmgr[30707]: 600E33A7F3: from=<darren.hoch@litemail.org>, size=1009, nrcpt=1 (queue active) Mar 17 21:44:10 asaph spamd[30274]: connection from asaph [127.0.0.1] at port 32906 Mar 17 21:44:11 asaph spamd[30788]: info: setuid to darren succeeded Mar 17 21:44:11 asaph spamd[30788]: Creating default_prefs [/home/darren/.spamassassin/user_prefs] Mar 17 21:44:11 asaph spamd[30788]: Created user preferences file: /home/darren/.spamassassin/user_prefs Mar 17 21:44:11 asaph spamd[30788]: processing message <2050.67.154.138.34.1079588774.squirrel@216.34.200.41> for darren:500. Mar 17 21:48:26 asaph postfix/local[30814]: B0F7C3B1F7: to=<darren@rh.myhopechapel.net>, relay=local, delay=1, status=sent ("|/usr/bin/maildrop -d "$USER" -f "$SENDER" "$EXTENSION")
|
Links and References:
Thanks to Robin Whittle (
rw@firstpr.com.au) for great documentation on
all of this!
http://www.firstpr.com.au/web-mail/
http://da.andaka.org/Doku/imapspamfilter.html#maildrop
http://spamassassin.org/sitewide.html
http://ebullient.haaser.com/archives/000210.php
http://buffy.riseup.net/introduction/
|