There is a new revision of this tutorial available for Ubuntu 13.10 (Saucy Salamander).
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
Virtual Users And Domains With Postfix, Courier And MySQL (Ubuntu 7.10)
Author: Falko Timme
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 7.10 Server (Gutsy Gibbon), so you should set up a basic Ubuntu 7.10 server installation before you continue with this tutorial (e.g. as shown on the pages 1 - 3 in this tutorial: The Perfect Server - Ubuntu Gutsy Gibbon (Ubuntu 7.10)). 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.
Make sure that you are logged in as root (type in
to become root), because we must run all the steps from this tutorial as root user.
2 Install Postfix, Courier, Saslauthd, MySQL, phpMyAdmin
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-2 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:
New password for the MySQL "root" user: <-- yourrootsqlpassword
Create directories for web-based administration ? <-- No
General type of mail configuration: <-- Internet Site
System mail name: <-- server1.example.com
SSL certificate required <-- Ok
Web server to reconfigure automatically: <-- apache2
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-server-dev-8.2 po-debconf dpatch libmysqlclient15-dev lsb-release libcdb-dev libdb4.5-dev
apt-get source postfix
(Make sure you use the correct Postfix version in the following commands. I have Postfix 2.4.5 installed. You can find out your Postfix version by running
postconf -d | grep mail_version
The output should look like this:
root@server1:~# postconf -d | grep mail_version
mail_version = 2.4.5
milter_macro_v = $mail_name $mail_version
patch -p1 < ../postfix-2.4.5-vda-ng.patch
You might see a warning like this at the end of the dpkg-buildpackage command:
(WARNING: Failed to sign .dsc and .changes file)
You can ignore this message.
Now we go one directory up, that's where the new .deb packages have been created:
shows you the available packages:
root@server1:/usr/src# ls -l
drwxr-xr-x 19 root src 4096 2007-11-16 14:33 postfix-2.4.5
-rw-r--r-- 1 root src 222693 2007-11-16 14:30 postfix_2.4.5-3ubuntu1.diff.gz
-rw-r--r-- 1 root src 663 2007-11-16 14:30 postfix_2.4.5-3ubuntu1.dsc
-rw-r--r-- 1 root src 1783 2007-11-16 14:33 postfix_2.4.5-3ubuntu1_i386.changes
-rw-r--r-- 1 root src 1123668 2007-11-16 14:33 postfix_2.4.5-3ubuntu1_i386.deb
-rw-r--r-- 1 root src 2934634 2007-08-03 19:53 postfix_2.4.5.orig.tar.gz
-rw-r--r-- 1 root src 57055 2007-08-02 01:13 postfix-2.4.5-vda-ng.patch
-rw-r--r-- 1 root src 38078 2007-11-16 14:33 postfix-cdb_2.4.5-3ubuntu1_i386.deb
-rw-r--r-- 1 root src 133642 2007-11-16 14:33 postfix-dev_2.4.5-3ubuntu1_all.deb
-rw-r--r-- 1 root src 826202 2007-11-16 14:33 postfix-doc_2.4.5-3ubuntu1_all.deb
-rw-r--r-- 1 root src 44340 2007-11-16 14:33 postfix-ldap_2.4.5-3ubuntu1_i386.deb
-rw-r--r-- 1 root src 40118 2007-11-16 14:33 postfix-mysql_2.4.5-3ubuntu1_i386.deb
-rw-r--r-- 1 root src 39956 2007-11-16 14:33 postfix-pcre_2.4.5-3ubuntu1_i386.deb
-rw-r--r-- 1 root src 40190 2007-11-16 14:33 postfix-pgsql_2.4.5-3ubuntu1_i386.deb
Pick the postfix and postfix-mysql packages and install them like this:
dpkg -i postfix_2.4.5-3ubuntu1_i386.deb
dpkg -i postfix-mysql_2.4.5-3ubuntu1_i386.deb