PostfixCompleteVirtualMailSystemHowto

Differences between revisions 24 and 25
Revision 24 as of 2006-03-17 08:59:34
Size: 11743
Editor: 2
Comment:
Revision 25 as of 2006-03-17 10:22:28
Size: 12719
Editor: 2
Comment:
Deletions are marked like this. Additions are marked like this.
Line 57: Line 57:
    * webmin-1.230
    * postfix-2.2.5
    * postgresql-8.0.4
    * apache-2.0.54-r31
    * php-4.4.0-r4
    * mod_php-4.4.0-r9
    * postfixadmin-2.1.0
    * courier-imap-4.0.1
    * courier-authlib-0.57-r1
    * cyrus-sasl-2.1.20-r2
    * ispell-3.2.06-r6
    * squirrelmail-1.4.5
    * awstats-6.5
    * amavisd-new-2.3.3-r2
    * spamassassin-3.1.0
    * MailZu-0.6RC3
    * razor-2.77
    * dcc-1.3.16
    * pyzor-0.4.0-r1
    * sqlgrey-1.6.7
    * sgwi-0.6
    * clamav-0.87.1




== The Big Pictire =
The following packages are need to implement our system and most of these packages are in APT repositories. In our installation section you will learn how to install and configure each.

    * webmin
    * postfix
    * mysql
    * apache
    * Php
    * mod_php
    * postfixadmin
    * ourier-imap
    * courier-authlib
    * cyrus-sasl
    * ispell
    * squirrelmail
    * awstats
    * amavisd-new
    * spamassassin
    * MailZu
    * razor
    * dcc
    * pyzor
    * sqlgrey
    * sgwi
    * clamav

== The Big Pictire ==

The following figure shows the big picture of our setup. If you look at it carefully the figure itself is self explanatory.
Line 86: Line 87:

In our setup

 * '''Postfix''' Mail Transfer Agent receives emails via the SMTP protocol and delivers them to different places on your hard disk.

 * '''MySQL''' database server that stores the information to control the behaviour of postfix. It knows about users, domains, email forwardings and passwords.

 * '''Courier''' is a standalone mail server just like Postfix but we just use its POP3/IMAP server component to let users access the mailboxes.

 * '''SASL''', the Cyrus library is using to authenticate your users who are dialed in at another ISP while they are on the road they get an IP address outside of your network. Your mail server however only trusts local IP addresses. The SASL ,'''Simple Authentication and Security Layer''', adds authentication to SMTP and makes your mail server trust them.

Abstract

There are many howtos in the Internet about setting up mail servers and various people has various choice of MTAs. Some like, Qmail, while some like Postfix or Exim. I have been using Qmail for a long time and it is an excellent MTA. The way the Qmail is licensed and distributed that there are no binary packages so that users can easily setup with their favorite distribution, and installing basic Qmail setup even is very difficult since users need applied various patches and tweaks etc. With all these hassles Qmail is the preferred choice of many geeks, no argument . The decision behind this guide is to use Postfix,an equally secure and fast MTA like Qmail, it is easy to configure and setup a [https://wiki.ubuntu.com/PostfixBasicSetupHowto basic system] in any Linux distribution. Postfix has many add-ons and support Maildir format, PostgreSQL and MySQL backend for storing and managing virtual domains very easily. This setup will be a complete virtual mail domain systems , with anti-virus and spam filtering for ISPs , hosting companies, and individual corporations who wish to use Ubuntu Linux as there preferred server platform.

System Overview

It is important to know how our system works before going to install. A virtual mail system needs to be able to handle email for numerous domains with multiple users over a variety of interfaces. When you handle multiple domains within the same mail system it presents you some management issues. We have to answer these issuses using our technology. Assume ,for example you may have following questions to answer.

  • What will you do if you have two users which require same username for different domains?
  • If you are providing imap access and smtp-auth, how do combine the various authentication daemons into a single system?
  • How do you provide security for the numerous components that comprise the system?
  • How do you manage all these issues together?
  • What we can do, if users are asking their own spam filtering policies.
  • Individual domain administrators are asiking a web-based interface to manage their mail domains
  • How do you setup a web-based management system for Postfix?
  • Each user needs a web-base interface to change his mail account's password
  • How you are going backup user account database and disater recovery?.
  • Utilizing ssl for transport layer security
  • Handle mailing lists for any domain

Don't be panic, I will answer all these questions. Be happy and continue to read this howto.

What You Get

  • Web based system administration
  • Unlimited number of domains
  • Virtual mail users without the need for shell accounts
  • Domain specific user names
  • Mailbox quotas
  • Web access to email accounts
  • Web base interface to change user passwords
  • IMAP and POP3 support
  • SMTP Authentication for secure relaying
  • SSL for transport layer security
  • Strong SPAM filtering
  • Anti-Virus filtering
  • Log Analysis

Packages Required

The following packages are need to implement our system and most of these packages are in APT repositories. In our installation section you will learn how to install and configure each.

  • webmin
  • postfix
  • mysql
  • apache
  • Php
  • mod_php
  • postfixadmin
  • ourier-imap
  • courier-authlib
  • cyrus-sasl
  • ispell
  • squirrelmail
  • awstats
  • amavisd-new
  • spamassassin
  • MailZu

  • razor
  • dcc
  • pyzor
  • sqlgrey
  • sgwi
  • clamav

The Big Pictire

The following figure shows the big picture of our setup. If you look at it carefully the figure itself is self explanatory.

attachment:CompleteSetupOverview.png

In our setup

  • Postfix Mail Transfer Agent receives emails via the SMTP protocol and delivers them to different places on your hard disk.

  • MySQL database server that stores the information to control the behaviour of postfix. It knows about users, domains, email forwardings and passwords.

  • Courier is a standalone mail server just like Postfix but we just use its POP3/IMAP server component to let users access the mailboxes.

  • SASL, the Cyrus library is using to authenticate your users who are dialed in at another ISP while they are on the road they get an IP address outside of your network. Your mail server however only trusts local IP addresses. The SASL ,Simple Authentication and Security Layer, adds authentication to SMTP and makes your mail server trust them.

How Postfix Mappings Work?

The generic literal meaning of mapping is assign one value to another. What we have to map in Postfix is email user accounts or email address. One example is /etc/aliases, the local aliases or local system users mapping file used by Postfix. The syntax of this file is:

postmaster: root

This makes all the mails which are coming to postmaster@yourdomain.tld are redirected to root@yourdomain.tld. We can divide the above syntax to Left Hand Side LHS and Right Hand Side RHS. This RHS and LHS are common abbreviations which we usually used in mappings. The following table will make this idea even more clear.

LHS

RHS

postmaster:

root

attachment:IconHint.png

Usually we do not use colon(:) in LHS for Postfix and this has been done for backward compatibility with historical reasons. The local alias file is a special file that is compiled with newaliases command but not with usual Postfix mapping command postmap

With a basic default Postfix installation we use text file for mappings. We write the mappings into this file and then convert it into a hash file using postmap command. For example, assume that we need to map our virtual mailboxes in a file called /etc/Postfix/virtual_mailboxes. The syntax of this file look like:

info@domain1.com sigiri
info@domain2.com kala

You may have noticed that we don't have colon(:) in the LHS of the mappings file

Then you need to run:

postmap /etc/postfix/virtual_mailboxes

You can access this mappings in the Postfix configuration file using the code:

virtual_mailbox_maps=hash:/etc/postfix/virtual_mailboxes

In our setup , we will replace this text mapping files by PostgreSQL tables. Our intention is to make data handling lot more flexible, robust, and scalable. But as database tables usually contain more than just two columns you will need to tell Postfix which column is meant to be the LHS and which is the RHS. For same virtual_mailbox file can be defined in a text file 'like this:

user = postfix
password = YJiNLQtubgnOE
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'

Let's assume that we save this data in a file called /etc/postfix/mysql_virtual_mailbox_maps.cf.

You can use this mappings in postfix using the following entry in main.cf file.

virtual_mailbox_maps = mysql:/usr/local/etc/postfix/pgsql_virtual_mailbox_maps.cf

The LHS of the mapping is defined as where_field and the RHS is defined as select_field. In this example we will map the

maildir

column to the username column. The other fields in this definition file are user that needs to connect to the PostgresSQL database, password that MySQL user, dbname, the name of the MySQL database, table ,the name of the table in PostgreSQL database and hosts, the name of the server that MySQL runs on. The following tables may clear the idea even more better.

LHS

RHS

select_filed

where_filed

maildir

username

Other fields:

Database User

Database User's Password

Database Name

Database Table

Database Host

postfix

YJiNLQtubgnOE

postfix

mailbox

localhost

How Postfix Virtual Domains Work?

Understanding how virtual domains work is very important to understand how our virtual mail setup works.

There are two types of domains in Postfix.

  • Local domains: All domains which are listed as mydestination are treated as local domains by Postfix. Emails for local domains are delivered to system users which are listed in /etc/passwd file and these mails are spooled in /var/mail directory.

  • Virtual domains: In addition to the local domains Postfix can deliver mails for virtual domains. Not like local domains, Postfix will let us to handle virtual domains in a very flexible manner. The good thing is with virtual domains is that we do not need system account in /etc/passwd for each and every mail account. This provides us a way to handle thousands of mail accounts very easily in our mail server system. The mapping which we discussed above is used to handle mail account information. You can use MySQL, PostgreSQL , or LDAP for the user account management. In our setup we use PostgreSQL backend to manage user accounts of virtual domains. Postfix handles virtual domains as two different categories and need to understand how they work.

    • Virtual alias domains: These domains are used to forward or alias mails from one email address to another email address. Such domains can be used receive mailboxes and store on your hard disk. You do not necessarily need to use virtual alias domains in your setup. Instead we can user virtual_alias_maps even if the domains are not listed as virtual alias domains. The virtual_alias_maps is a general-purpose redirection mapping that works for everything that passes your system including local domains.

    • Virtual mailbox domains: Postfix uses these domains to receive mails for users under the domains and store them in the mailboxes on the hard disk. This is parameter which will simply tell Postfix to receive the mails on behalf of the domain and store them in each user's mailbox. The virtual_mailbox_maps mapping is used by Postfix to determine the location of the mailbox on your hard disk. Please remember that you can still use the virtual_alias_maps mapping to forward email to other mailboxes or external email addresses so not every user on that domain must actually have a mailbox but can also just have the email forwarded somewhere else.

attachment:IconHint.png

It is important to understand that a domain is either a virtual alias domain or a virtual mailbox domain or a local domain. If you make a domain a virtual alias domain you will not be able to receive email for that domain on your server. On the contrary you can use the virtual_alias_maps to forward/alias email for both types of domain. So the virtual mailbox domains are generally the more flexible to use.

attachment:IconWarning.png

A domain can either be virtual or local and you can not use one domain in the both of these roles. Please never both. So if you decide you want your default domain be a virtual domain then remove it from the mydestination definition. Just leave it blank or set it to mydestination=localhost. Email addresses like root@localhost would then be delivered to the local root user.

Getting Started

System Setup and Packages

Basic Mail Setup

Admin Support Systems

MySQL

Postfix

Postfix to MySQL

Enhanced Mail Services

Postfixadmin

Courier-IMAP and Authentication Services

SMTP Authentication

Web Access

Refining the Setup

Anti-Spam Configuration

Installing Amavisd and SpamAssassin

Quarantine and Spam Management

Auto and Per-Recipient White/Black Lists

Amavis/Spamassassin UI

GreyListing

Distributed and Collaborative Networks

Anti-Virus Configuration

Configuring for ClamAV

Log Analyzer

Install and Configure AWStats

Wrapping it Up

Final Changes and Troubleshooting

Howto created by: ChinthakaDeshapriya.


CategoryDocumentation

PostfixCompleteVirtualMailSystemHowto (last edited 2008-08-06 16:17:41 by localhost)