There is a new revision of this tutorial available for Ubuntu 13.10 (Saucy Salamander).
Virtual Users And Domains With Postfix, Courier And MySQL (Ubuntu 6.10 Edgy Eft)
This tutorial exists for these OS versions
- Ubuntu 13.10 (Saucy Salamander)
- Ubuntu 14.04 LTS (Trusty Tahr)
- Ubuntu 12.10 (Quantal Quetzal)
- Ubuntu 12.04 LTS (Precise Pangolin)
- Ubuntu 11.10 (Oneiric Ocelot)
- Ubuntu 11.04 (Natty Narwhal)
On this page
This tutorial is Copyright (c) 2007 by Falko Timme. It is derived from a tutorial from Christoph Haas which you can find at http://workaround.org. 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 mail server based on Postfix 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.
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 Ubuntu 6.10 (Edgy Eft), so you should set up a basic Ubuntu installation before you continue with this tutorial. The system should have a static IP address. I use 192.168.0.100 as my IP address in this tutorial and server1.example.com as the hostname.
I prefer to do all the steps here as the root user. So if you haven't already created a root login, you should do so now:
sudo passwd root
Afterwards, log in as root:
If you would like to work as a normal user instead of root, remember to put sudo in front of all the commands shown in this tutorial. So when I run
you should run
sudo apt-get update
2 Install Postfix, Courier, Saslauthd, MySQL, phpMyAdmin
Before we install these packages, we need to modify /etc/apt/sources.list and enable the universe repository, so make sure you have the following lines enabled:
[...] deb http://de.archive.ubuntu.com/ubuntu/ edgy universe deb-src http://de.archive.ubuntu.com/ubuntu/ edgy universe [...]
to update your packages database.
To install Postfix, Courier, Saslauthd, MySQL, and phpMyAdmin, we simply run
apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl postfix-tls libsasl2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql
You will be asked a few questions:
Create directories for web-based administration ? <-- No
General type of configuration? <-- Internet Site
Mail name? <-- server1.example.com
SSL certificate required <-- Ok
3 Apply The Quota Patch To Postfix
We have to get the Postfix sources, patch it with the quota patch, build new Postfix .deb packages and install those .deb packages:
apt-get install build-essential dpkg-dev fakeroot debhelper libgdbm-dev libldap2-dev libpcre3-dev libssl-dev libsasl2-dev postgresql-dev po-debconf dpatch libdb4.3-dev libmysqlclient15-dev
apt-get source postfix
(Make sure you use the correct Postfix version in the following commands. I have Postfix 2.3.3 installed. You can find out your Postfix version by running
postconf -d | grep mail_version
patch -p1 < ../postfix-2.3.3-vda.patch
dpkg -i postfix_2.3.3-1_i386.deb
dpkg -i postfix-mysql_2.3.3-1_i386.deb