Mail Server using Postfix and Courier

Introduction
This document will help you setup Postfix, Courier, CyrusSASL, Amavis, and Spamassassin to process mail for aliases, domains, and mailboxes within a MySQL database. The config files can be somewhat daunting, but strict adherence to this guide should get you to a point you can customize and experiment on your own!

Emerge Software
As always, its good practice to ensure your portage tree is up to date (emerge --sync) and your World is up to date

MySQL Data
Create the following tables: --- --- Purpose: Create alias, domain, mailbox, and vacation tables --- Relation: ---    The domain table lists the domains that postfix will ---    accept mail for. Once it accepts the mail it either finds ---    the matching mailbox entry or finds an alias entry that ---    matches the recipient with a valid linked mailbox entry. --- CREATE TABLE IF NOT EXISTS `alias` ( `address` varchar(255) NOT NULL default ,  `goto` text NOT NULL,  `domain` varchar(255) NOT NULL default ,  `created` datetime NOT NULL default '0000-00-00 00:00:00',  `modified` datetime NOT NULL default '0000-00-00 00:00:00',  `active` tinyint(1) NOT NULL default '1',  PRIMARY KEY  (`address`),  KEY `address` (`address`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Aliases';

CREATE TABLE IF NOT EXISTS `domain` ( `domain` varchar(255) NOT NULL default ,  `description` varchar(255) NOT NULL default ,  `aliases` int(10) NOT NULL default '0',  `mailboxes` int(10) NOT NULL default '0',  `maxquota` int(10) NOT NULL default '0',  `transport` varchar(255) default NULL,  `backupmx` tinyint(1) NOT NULL default '0',  `created` datetime NOT NULL default '0000-00-00 00:00:00',  `modified` datetime NOT NULL default '0000-00-00 00:00:00',  `active` tinyint(1) NOT NULL default '1',  PRIMARY KEY  (`domain`),  KEY `domain` (`domain`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Domains';

CREATE TABLE IF NOT EXISTS `mailbox` ( `username` varchar(255) NOT NULL default ,  `password` varchar(255) NOT NULL default ,  `name` varchar(255) NOT NULL default ,  `maildir` varchar(255) NOT NULL default ,  `quota` int(10) NOT NULL default '0',  `domain` varchar(255) NOT NULL default '',  `created` datetime NOT NULL default '0000-00-00 00:00:00',  `modified` datetime NOT NULL default '0000-00-00 00:00:00',  `active` tinyint(1) NOT NULL default '1',  PRIMARY KEY  (`username`),  KEY `username` (`username`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Mailboxes';

CREATE TABLE IF NOT EXISTS `vacation` ( `email` varchar(255) NOT NULL default ,  `subject` varchar(255) NOT NULL default ,  `body` text NOT NULL,  `cache` text NOT NULL,  `domain` varchar(255) NOT NULL default '',  `created` datetime NOT NULL default '0000-00-00 00:00:00',  `active` tinyint(1) NOT NULL default '1',  PRIMARY KEY  (`email`),  KEY `email` (`email`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Postfix Admin - Virtual Vacation';

Here is some example data: --- --- Purpose: (demo) Inserts some default boxes --- INSERT INTO `domain` (`domain`, `description`, `aliases`, `mailboxes`, `maxquota`, `transport`, `backupmx`, `created`, `modified`, `active`) VALUES('example.com', 'Example, Inc.', 0, 0, 0, NULL, 0, NOW, '0000-00-00 00:00:00', 1); INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `domain`, `created`, `modified`, `active`) VALUES('jose.dominguez@example.com', ENCRYPT('password'), 'Jose Dominguez', 'example.com/jose/', 0, 'example.com', NOW, '0000-00-00 00:00:00', 1); INSERT INTO `alias` (`address`, `goto`, `domain`, `created`, `modified`, `active`) VALUES('jose@example.com', 'jose.dominguez@example.com', 'example.com', NOW, '0000-00-00 00:00:00', 1);