Gentoo Wiki


Complete Virtual Mail Server

Getting Started

Basic Mail Setup

Enhanced Mail Services

Anti-Spam Configuration

Anti-Virus Configuration

Log Analyzer

Wrapping it Up



Wow, when I started this HOWTO, it was going to be a simple extension of the “Virtual Mailhosting System with Postfix Guide” written by Ken Nowack and Ezra Gorman. All I was going to do is change from MySQL to PostgreSQL, how much of a problem could that be?

After many hours of effort, about 8000 different configuration variations and having to try to read hints and tips from pages in almost every language you can imagine, I finally have it (Phew!). I have made every effort to validate that this configuration is correct but cannot guarantee it 100%, however it was close enough to get me running and believe me, I am no Linux expert.

Because this document is so long (over 100 pages in a4 paper format!), I have broken it into a number of sections in the hopes that it will be more manageable. Enjoy!

So What do I Get?

The purpose of this HOWTO is to establish a virtual mail system that can handle multiple domains with a variety of different interface options. This is not intended to be used by the average user who is looking for a mail client, this is a full-scale Mail Transfer Agent (MTA) intended for individuals who are hosting their own domains and/or need to provide support for virtual domains.

By the end of this HOWTO, you will have an easy method to manage a mail server that supports:

The real plus is that all of this is managed by a single backend Postgres database.

Additions to this document

(2006-10-07, by mknappe)

This document was by far the best I could find for setting up a virtual mail system including all kind of spam and virus filtering. But I chose a different approach and I am going to comment parts of this HOWTO with my own experiences. The main differences are:

I am additionally going to explain certain configuration options and why they are important and maybe in the near future I will provide you with a download link where you can get a PHP application to administer your mail database. All my comments will start with (date of writing, by mknappe) and end with (/addition)


Getting Started

System Setup and Packages

This section outlines my system setup (a multi-server implementation) as well as the core packages that were used. This is a MUST READ before you carry on any further (don't worry, it's short).

Basic Mail Setup

Admin Support Systems

Webmin and Apache were both key tools in getting through testing and getting this to hang together. While I will not take you through the details of an Apache/PHP setup there is good information in here all the same.


All the details we need to ensure Postgres is installed, the schema created and is properly configured to backend our solution.


The basic Postfix installation to confirm that it is installed and working. We will get to the more advanced stuff further on.

Postfix to Postgres

Connecting our two systems together with some add-on features.

Enhanced Mail Services


While I decided not to use Postfixadmin in my final setup, I still felt it was worth including this as many may find it quite useful.

Courier-IMAP and Authentication Services

Installation and setup of secure IMAP and POP3 services using courier-imap.

SMTP Authentication

To ensure my mailserver does not get abused, I require authentication before users are allowed to send any outgoing mail.

Web Access

We can provide web access to individual mail accounts with Squirrelmail.

Refining the Setup

Using some of the out-of-the-box features of Postfix we can refine the settings to help eliminate some spam and make some minor performance adjustments.

Anti-Spam Configuration

Installing Amavisd and SpamAssassin

Setup Amavisd, SpamAssasin and Postfix to filter your emails before delivery. If all goes well, neither spam nor virus' should see the inside of a mailbox.

Quarantine and Spam Management

We have a database, so we might as well use it. All undesirable mail will be quarantined in the database. A good option for per-user access and management.

Auto and Per-Recipient White/Black Lists

As above, we will configure the system to store your per-recipient white and black lists as well as Auto Whitelisting in the Postgres database. This is a little more limited as I have not found a user interface to support the schema yet.

Amavis/Spamassassin UI

A base interface does exist, but it was not all encompassing enough for my needs. Still it shows promise so I will setup you through it.


A decent feature that can really cut down on your spam. Easy to install and can have a significant impact on spam.

Distributed and Collaborative Networks

Connections to some of the more popular (and yes, free) networks available in the battle against spam.

Anti-Virus Configuration

Configuring for ClamAV

With the infrastructure we have to this point, it is fairly easy to tie in ClamAV as a virus scanner for our system.

Log Analyzer

Install and Configure AWStats

With all the work you've done, you will certainly want to be able to analyze the fruits of your labour. AWstats will allow us to summarize the activity on both our mail server and web site.

Wrapping it Up

Final Changes and Troubleshooting

A few minor things to complete the setup along with some useful places to look if you run into problems.

Retrieved from ""

Last modified: Tue, 19 Aug 2008 06:41:00 +0000 Hits: 58,562