Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Fedora 18 x86_64)

This tutorial is Copyright (c) 2013 by Falko Timme. It is derived from a tutorial from Christoph Haas which you can find at You are free to use this tutorial under the Creative Commons license 2.5 or any later version.

This document describes how to install a Postfix mail server that is based on virtual users and domains, i.e. users and domains that are in a MySQL database. I'll also demonstrate the installation and configuration of Courier (Courier-POP3, Courier-IMAP), so that Courier can authenticate against the same MySQL database Postfix uses.

The resulting Postfix server is capable of SMTP-AUTH and TLS and quota (quota is not built into Postfix by default, I'll show how to patch your Postfix appropriately). Passwords are stored in encrypted form in the database (most documents I found were dealing with plain text passwords which is a security risk). In addition to that, this tutorial covers the installation of Amavisd, SpamAssassin and ClamAV so that emails will be scanned for spam and viruses. I will also show how to install SquirrelMail as a webmail interface so that users can read and send emails and change their passwords.

The advantage of such a "virtual" setup (virtual users and domains in a MySQL database) is that it is far more performant than a setup that is based on "real" system users. With this virtual setup your mail server can handle thousands of domains and users. Besides, it is easier to administrate because you only have to deal with the MySQL database when you add new users/domains or edit existing ones. No more postmap commands to create db files, no more reloading of Postfix, etc. For the administration of the MySQL database you can use web based tools like phpMyAdmin which will also be installed in this howto. The third advantage is that users have an email address as user name (instead of a user name + an email address) which is easier to understand and keep in mind.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!


1 Preliminary Note

This tutorial is based on Fedora 18 x86_64, so you should set up a basic Fedora 18 server installation before you continue with this tutorial. The system should have a static IP address. I use as my IP address in this tutorial and as the hostname.

You should make sure that the firewall is off (at least for now).

Also make sure that SELinux is disabled:

Edit /etc/selinux/config and set SELINUX=disabled:

vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.

Afterwards we must reboot the system:



2 Install Some Software

First we update our existing packages on the system:

yum update

Now we install some software that we need later on:

yum groupinstall 'Development Tools'

yum groupinstall 'Development Libraries'


3 Install Apache, MySQL, phpMyAdmin

This can all be installed with one single command (including the packages we need to build Courier-IMAP):

yum install ntp httpd mod_ssl mysql-server php php-mysql php-mbstring rpm-build gcc mysql-devel openssl-devel cyrus-sasl-devel pkgconfig zlib-devel phpMyAdmin pcre-devel openldap-devel postgresql-devel expect libtool-ltdl-devel openldap-servers libtool gdbm-devel pam-devel gamin-devel libidn-devel sqlite-devel


4 Install Courier-IMAP, Courier-Authlib, And Maildrop

Unfortunately there are no rpm packages for Courier-IMAP, Courier-Authlib, and Maildrop, therefore we have to build them ourselves.

RPM packages should not be built as root; courier-imap will even refuse to compile if it detects that the compilation is run as the root user. Therefore we create a normal user account now (falko in this example) and give him a password:

useradd -m -s /bin/bash falko
passwd falko

We will need the sudo command later on so that the user falko can compile and install the rpm packages. But first, we must allow falko to run all commands using sudo:



In the file that opens there's a line root ALL=(ALL) ALL. Add a similar line for falko just below that line:

## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
falko   ALL=(ALL)       ALL

Now we are ready to build our rpm package. First become the user falko:

su falko

Next we create our build environment:

mkdir $HOME/rpm
mkdir $HOME/rpm/SOURCES
mkdir $HOME/rpm/SPECS
mkdir $HOME/rpm/BUILD
mkdir $HOME/rpm/SRPMS
mkdir $HOME/rpm/RPMS
mkdir $HOME/rpm/RPMS/i386
mkdir $HOME/rpm/RPMS/x86_64

echo "%_topdir $HOME/rpm" >> $HOME/.rpmmacros

Now we create a downloads directory and download the source files from

mkdir $HOME/downloads
cd $HOME/downloads


Now (still in $HOME/downloads) we can build courier-authlib:

sudo rpmbuild -ta courier-authlib-0.65.0.tar.bz2

After the build process, the rpm packages can be found in /root/rpmbuild/RPMS/x86_64 (/root/rpmbuild/RPMS/i386 if you are on an i386 system). The command

sudo ls -l /root/rpmbuild/RPMS/x86_64

shows you the available rpm packages:

[[email protected] downloads]$ sudo ls -l /root/rpmbuild/RPMS/x86_64
total 616
-rw-r--r-- 1 root root 140580 Jan 31 17:14 courier-authlib-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root 324148 Jan 31 17:14 courier-authlib-debuginfo-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  38928 Jan 31 17:14 courier-authlib-devel-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  18756 Jan 31 17:14 courier-authlib-ldap-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  13044 Jan 31 17:14 courier-authlib-mysql-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  14208 Jan 31 17:14 courier-authlib-pgsql-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root   9356 Jan 31 17:14 courier-authlib-pipe-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  11696 Jan 31 17:14 courier-authlib-sqlite-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  37580 Jan 31 17:14 courier-authlib-userdb-0.65.0-1.fc18.x86_64.rpm
[[email protected] downloads]$

Select the ones you want to install, and install them like this:

sudo rpm -ivh /root/rpmbuild/RPMS/x86_64/courier-authlib-0.65.0-1.fc18.x86_64.rpm /root/rpmbuild/RPMS/x86_64/courier-authlib-mysql-0.65.0-1.fc18.x86_64.rpm /root/rpmbuild/RPMS/x86_64/courier-authlib-devel-0.65.0-1.fc18.x86_64.rpm

Now we go back to our downloads directory:

cd $HOME/downloads

Run the following commands to create required directories/change directory permissions (because otherwise the build process for Courier-Imap will fail):

sudo mkdir /var/cache/ccache/tmp
sudo chmod o+rwx /var/cache/ccache/
sudo chmod 777 /var/cache/ccache/tmp

Now run rpmbuild again, this time without sudo, otherwise the compilation will fail because it was run as root:

rpmbuild -ta courier-imap-4.12.0.tar.bz2

After the build process, the rpm packages can be found in $HOME/rpm/RPMS/x86_64 ($HOME/rpm/RPMS/i386 if you are on an i386 system):

cd $HOME/rpm/RPMS/x86_64

The command

ls -l

shows you the available rpm packages:

[[email protected] x86_64]$ ls -l
total 1256
-rw-rw-r-- 1 falko falko 344996 Jan 31 17:19 courier-imap-4.12.0-1.18.x86_64.rpm
-rw-rw-r-- 1 falko falko 934056 Jan 31 17:19 courier-imap-debuginfo-4.12.0-1.18.x86_64.rpm
[[email protected] x86_64]$

You can install courier-imap like this:

sudo rpm -ivh courier-imap-4.12.0-1.18.x86_64.rpm

Now we go back to our downloads directory:

cd $HOME/downloads

and run rpmbuild again, this time to build a maildrop package:

sudo rpmbuild -ta maildrop-2.6.0.tar.bz2

After the build process, the rpm packages can be found in /root/rpmbuild/RPMS/x86_64 (/root/rpmbuild/RPMS/i386 if you are on an i386 system). The command

sudo ls -l /root/rpmbuild/RPMS/x86_64

shows you the available rpm packages:

[[email protected] downloads]$ sudo ls -l /root/rpmbuild/RPMS/x86_64
total 1880
-rw-r--r-- 1 root root 140580 Jan 31 17:14 courier-authlib-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root 324148 Jan 31 17:14 courier-authlib-debuginfo-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  38928 Jan 31 17:14 courier-authlib-devel-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  18756 Jan 31 17:14 courier-authlib-ldap-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  13044 Jan 31 17:14 courier-authlib-mysql-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  14208 Jan 31 17:14 courier-authlib-pgsql-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root   9356 Jan 31 17:14 courier-authlib-pipe-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  11696 Jan 31 17:14 courier-authlib-sqlite-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  37580 Jan 31 17:14 courier-authlib-userdb-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root 309340 Jan 31 17:23 maildrop-2.6.0-1.18.x86_64.rpm
-rw-r--r-- 1 root root 805928 Jan 31 17:23 maildrop-debuginfo-2.6.0-1.18.x86_64.rpm
-rw-r--r-- 1 root root 105756 Jan 31 17:23 maildrop-devel-2.6.0-1.18.x86_64.rpm
-rw-r--r-- 1 root root  66416 Jan 31 17:23 maildrop-man-2.6.0-1.18.x86_64.rpm
[[email protected] downloads]$

You can now install maildrop like this:

sudo rpm -ivh /root/rpmbuild/RPMS/x86_64/maildrop-2.6.0-1.18.x86_64.rpm

After you have compiled and installed all needed packages, you can become root again by typing



5 Apply Quota Patch To Postfix

We have to get the Postfix source rpm, patch it with the quota patch, build a new Postfix rpm package and install it.

cd /usr/src
rpm -ivh postfix-2.9.4-3.fc18.src.rpm

The last command will show some warnings that you can ignore:

warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root

cd /root/rpmbuild/SOURCES
cd /root/rpmbuild/SPECS/

Now we must edit the file postfix.spec:

vi postfix.spec

Add Patch0: postfix-vda-v11-2.9.4.patch to the # Patches stanza, and %patch0 -p1 -b .vda-v11 to the %setup -q stanza:

# Patches

Patch0: postfix-vda-v11-2.9.4.patch
Patch1: postfix-2.7.0-config.patch
Patch2: postfix-2.6.1-files.patch
Patch3: postfix-alternatives.patch
Patch8: postfix-large-fs.patch
Patch9: pflogsumm-1.1.3-datecalc.patch
%setup -q
# Apply obligatory patches
%patch0 -p1 -b .vda-v11
%patch1 -p1 -b .config
%patch2 -p1 -b .files
%patch3 -p1 -b .alternatives
%patch8 -p1 -b .large-fs

Before we build the new Postfix package, we need to install its requirement libdb-devel - and because libdb-devel conflicts with db4-devel, we must remove that package first:

yum remove db4-devel

yum install libdb-devel

Then we build our new Postfix rpm package with quota and MySQL support:

rpmbuild -ba postfix.spec

Our Postfix rpm package is created in /root/rpmbuild/RPMS/x86_64 (/root/rpmbuild/RPMS/i386 if you are on an i386 system), so we go there:

cd /root/rpmbuild/RPMS/x86_64

The command

ls -l

shows you the available packages:

[[email protected] x86_64]# ls -l
total 10504
-rw-r--r-- 1 root root  140580 Jan 31 17:14 courier-authlib-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  324148 Jan 31 17:14 courier-authlib-debuginfo-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root   38928 Jan 31 17:14 courier-authlib-devel-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root   18756 Jan 31 17:14 courier-authlib-ldap-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root   13044 Jan 31 17:14 courier-authlib-mysql-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root   14208 Jan 31 17:14 courier-authlib-pgsql-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root    9356 Jan 31 17:14 courier-authlib-pipe-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root   11696 Jan 31 17:14 courier-authlib-sqlite-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root   37580 Jan 31 17:14 courier-authlib-userdb-0.65.0-1.fc18.x86_64.rpm
-rw-r--r-- 1 root root  309340 Jan 31 17:23 maildrop-2.6.0-1.18.x86_64.rpm
-rw-r--r-- 1 root root  805928 Jan 31 17:23 maildrop-debuginfo-2.6.0-1.18.x86_64.rpm
-rw-r--r-- 1 root root  105756 Jan 31 17:23 maildrop-devel-2.6.0-1.18.x86_64.rpm
-rw-r--r-- 1 root root   66416 Jan 31 17:23 maildrop-man-2.6.0-1.18.x86_64.rpm
-rw-r--r-- 1 root root 2553200 Jan 31 17:30 postfix-2.9.4-3.fc18.x86_64.rpm
-rw-r--r-- 1 root root 6203284 Jan 31 17:30 postfix-debuginfo-2.9.4-3.fc18.x86_64.rpm
-rw-r--r-- 1 root root   66108 Jan 31 17:30 postfix-perl-scripts-2.9.4-3.fc18.x86_64.rpm
[[email protected] x86_64]#

Pick the Postfix package and install it like this:

rpm -ivh postfix-2.9.4-3.fc18.x86_64.rpm

Share this page:

4 Comment(s)

Add comment



Need to install: yum install libtool-ltld-devel

Need to install: yum install expect

Need to install: yum install postgresql-devel

Need to install: yum install sqlite-devel

Need to install: yum install mysql-devel


yum install expect gdbm-devel pam-devel gamin-devel openssl-perl ghostscript mgetty-sendfax netpbm-progs pcre-devel libidn-devel


From: fly


This is a very good tutorial to show us the methods.

And i do it step by step. I have one question about Creat the mail folder. Everything is Ok but it can not generate the User Mail Folder at ../Vmail/  automatically. Mysql Is Ok, and i want to konw whether you  had met such a problem.

Best wishes


From: Cristian Sava

If you use this tutorial for Fedora 24 (adapt it please!) then visit

to get the link to the latest postfix-vda-v13-3.1.1.patch and adapt the specs file:


# PatchesPatch0: postfix-vda-v13-3.1.1.patchPatch1: postfix-3.0.0-config.patchPatch2: postfix-3.1.0-files.patchPatch3: postfix-3.1.0-alternatives.patchPatch4: postfix-3.1.0-large-fs.patchPatch9: pflogsumm-1.1.3-datecalc.patch[...]

%prep%setup -q# Apply obligatory patches%patch0 -p1 -b .vda-v13%patch1 -p1 -b .config%patch2 -p1 -b .files%patch3 -p1 -b .alternatives%patch4 -p1 -b .large-fs[...]