Building A Reliable Open Source Mail Server for CentOS 4

*UPDATED 01/2007 for CentOS 4.0

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). All binary packages created in this tutorial can be downloaded from:


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 CentOS 4 with the following packages:
    o Apache
    o PHP
    o Postfix
    o wget
Unbundled Software Requirements
o Courier IMAP 4.1.2 (
o Maildrop 2.0.3 (
o SpamAssassin 3.1.7 (
o Squirrelmail 1.4.9a (

Remove if already installed
o SpamAssassin
o perl-Mail-Spamassassin

Software Not Used
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

I. Install package dependencies. The postgres, mysql, and openldap packages are only needed to satisfy Courier Imap dependencies. These packages will not
 be needed or installed.
# yum update
# yum install postgresql-devel
# yum install mysql-devel
# yum install expect
# yum install fam-devel
# yum install openldap-servers
# yum install pcre-devel
# yum 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
$ 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

The source distributions contain RPM .spec files. These files are the core configuration for RPM packaging. The "rpmbuild" command
will extract the .spec file, unzip, compile, and package the source code. All that needs to be done next is install the binary RPMs
created in the rpmbuild/RPMS/i386 directory.
$ cd $HOME/rpmbuild/SOURCES
$ wget
$ wget
$ wget
$ rpmbuild -ta courier-authlib-0.59.1.tar.bz2
$ exit
# cd /home/darren/rpmbuild/RPMS/i386/
# rpm -ivh courier-authlib-0.59.1-1.i386.rpm
# rpm -ivh courier-authlib-devel-0.59.1-1.i386.rpm
$ su - darren

$ rpmbuild -ta courier-imap-4.1.2.tar.bz2
$ rpmbuild -ta maildrop-2.0.3.tar.bz2
$ cd rpmbuild/RPMS/i386
$ su
IV. Install and Enable the Courier IMAP and Maildrop Services
# rpm -ivh courier-imap-* maildrop-*
# chkconfig --add courier-imap
# chkconfig --add courier-authlib
# chkconfig courier-imap on
# chkconfig courier-authlib on
# service courier-imap start
# service courier-authlib start
# chmod 777 /var/spool/authdaemon
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/
myhostname =
mydomain =
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

VI. Download and Install SpamAssassin

There are a couple of Perl modules that must be installed (via RPM) in order for spamassassin-tools to work. Three of the modules
are included in the CentOS 4 distribution. The other two were taken from a sourceforge project that builds Perl module RPMS.
# su - darren
$ wget
$ rpmbuild -ta Mail-SpamAssassin-3.1.7.tar.gz
$ su

# cd rpmbuilds/RPMS/i386
# rpm -ivh perl-Mail-SpamAssassin-3.1.7-1.i386.rpm
# rpm -ivh spamassassin-3.1.7-1.i386.rpm
# chkconfig spamassassin on
# service spamassassin start
VII. Integrate Maildrop with SpamAssassin
# vi /etc/maildroprc
import SENDER
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 "!"
to "Maildir/.Spam"
$ chmod 600 $HOME/.mailfilter
IX. Install and configure Squirrelmail for Courier IMAP
# cd /usr/share/squirrelmail/conf
# ./


D. Set pre-defined settings for specific IMAP servers

Command >> D
SquirrelMail Configuration : Read: config.php


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...


Command >> S

Data saved in config.php
Press enter to continue...


Command >> q

# cd /etc/squirrelmail
# vi config_local.php

#$default_folder_prefix = '';

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
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/example
ErrorLog logs/error_log
CustomLog logs/access_log common

# 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/

XI. Logining into Squirrelmail

Point your web browser to

You should be at the Squirrelmail login page. Enter a valid Unix user account and pass. Each user needs to subscribe to both their Spam folders. This can be done by clicking on "Folders" at the top, selecting the Spam folders at the bottom of the page, and clicking on "Subscribe".

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[]
Mar 17 21:44:10 asaph postfix/smtpd[30781]: 600E33A7F3:[]
Mar 17 21:44:10 asaph postfix/cleanup[30783]: 600E33A7F3: message-id=<2050.
Mar 17 21:44:10 asaph postfix/smtpd[30781]: disconnect from[]
Mar 17 21:44:10 asaph postfix/nqmgr[30707]: 600E33A7F3: from=<>, size=1009,
 nrcpt=1 (queue active)
Mar 17 21:44:10 asaph spamd[30274]: connection from asaph [] 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/testuser/.spamassassin/user_prefs]
Mar 17 21:44:11 asaph spamd[30788]: Created user preferences file: /home/testuser/.spamassassin/user_prefs
Mar 17 21:44:11 asaph spamd[30788]: processing message <2050.>
for darren:500.
Mar 17 21:48:26 asaph postfix/local[30814]: B0F7C3B1F7: to=<>, relay=local, delay=1,
status=sent ("|/usr/bin/maildrop -d "$USER" -f "$SENDER" "$EXTENSION")

Links and References:

Thanks to Robin Whittle ( for great documentation on all of this!