Courier and Postfix with MySQL on Fedora Core

It is supposed to be a very fine email base that can be worked all the way up with admin interfaces. This would get a Fedora Core system with Postfix handling mail for virtual domains and accounts of which the details are stored on a MySQL database and the email files are on disk. Courier IMAP/POP will be used for email retrieval.

Requirements: Fedora Core 4 installed as “Server” with “Minimal” packages (do a full yum update before starting).

Downloading and Installing

a) Install the needed files available from yum repositories

Add Courier repository:

[enlartenment]
name=Enlartenment Repository for $releasever - $basearch
baseurl=http://www.enlartenment.com/packages/fedora/$releasever/$basearch/
enabled=1
gpgcheck=1

“yum -y install ntp httpd mysql-server php php-mysql rpm-build gcc expect libtool-ltdl gamin db4-devel irb openldap-devel mysql-devel openssl-devel cyrus-sasl-devel pcre-devel pkgconfig zlib-devel maildrop courier-imap courier-authlib-mysql”

b) Download and install phpMyAdmin RPM (Archive of Independent RedHat Contributors) from rpmfind.net

Change the MySQL root password

c) Download and install Postfix

* Download and install source RPM from rpmfind.net
* Edit /usr/src/redhat/SPECS/postfix.spec

%define MYSQL 1

* Build the package with “rpmbuild -bb /usr/src/redhat/SPECS/postfix.spec”
* Install the new Postfix RPM located in /usr/src/redhat/RPMS/i386/postfix

[ad]

Configuring

The main variables involved are the virtual user and the user id, virtual user’s group and group id, the hostname, the domain, local email user network’s ip range, sql server, the database to be used, the database user, email quota and possibly the cryptography too.

/etc/postfix/main.cf

myhostname = email-server.example.com
mydomain = example.com
mynetworks = 10.0.0.0/16
virtual_alias_maps=mysql:/etc/postfix/valiases-mysql
virtual_mailbox_domains=mysql:/etc/postfix/vdomains-mysql
virtual_mailbox_maps=mysql:/etc/postfix/vmailboxes-mysql
virtual_uid_maps=static:8008
virtual_gid_maps=static:8008
virtual_mailbox_base=/home/vmail
virtual_transport=virtual
virtual_mailbox_limit=1000000000
virtual_overquota_bounce = yes

/etc/postfix/master.cf

maildrop unix - n n - - pipe
flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}

/etc/postfix/vdomains-mysql

user = postfix
password = password
hosts = localhost
dbname = Email-database
table = domains
select_field = description
where_field = name

/etc/postfix/valiases-mysql

user = postfix
password = password
hosts = localhost
dbname = Email-database
table = forwards
select_field = goto
where_field = address

/etc/postfix/vmailboxes-mysql

user = postfix
password = password
hosts = localhost
dbname = Email-database
table = accounts
select_field = maildir
where_field = username

/etc/authlib/authdaemonrc

authmodulelist=”authmysql”
daemons=10

/etc/authlib/authmysql

MYSQL_SERVER localhost
MYSQL_USERNAME postfix
MYSQL_PASSWORD password
MYSQL_DATABASE Email-database
MYSQL_USER_TABLE accounts
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD ‘8008′
MYSQL_GID_FIELD ‘8008′
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD ‘/home/vmail’
MYSQL_NAME_FIELD name
MYSQL_MAILDIR_FIELD maildir
MYSQL_QUOTA_FIELD quota
MYSQL_WHERE_CLAUSE active=’1′

User Settings

Create user “vmail” and change the userid and groupid to 8008.
The user’s home directory will be the root for all virtual mail directories.

Database

Create database user “postfix” with permissions for the database “Email-database”
The following dump is the database structure (Rails convention).

CREATE DATABASE `Email-database` DEFAULT CHARACTER SET latin1 COLLATE
latin1_swedish_ci;
USE Email101;

CREATE TABLE `accounts` (

`id` int(11) NOT NULL,
`username` varchar(128) NOT NULL default ”,
`password` varchar(128) NOT NULL default ”,
`customer_id` int(11) default NULL,
`maildir` varchar(128) NOT NULL default ”,
`domain_id` int(11) NOT NULL default ‘0′,
`quota` int(11) NOT NULL default ‘10000000′,
`active` int(11) NOT NULL default ‘1′,
PRIMARY KEY (`id`)

) TYPE=MyISAM;

CREATE TABLE `domains` (

`id` int(11) NOT NULL,
`name` varchar(128) NOT NULL default ”,
`description` varchar(255) default NULL,
`active` int(11) NOT NULL default ‘1′,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
PRIMARY KEY (`id`)

) TYPE=MyISAM;

CREATE TABLE `forwards` (

`id` int(11) NOT NULL,
`address` varchar(128) NOT NULL default ”,
`goto` varchar(128) NOT NULL default ”,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
`active` int(11) NOT NULL default ‘1′,
PRIMARY KEY (`id`)

) TYPE=MyISAM;

Done

Start all applications, add a new domain and a user and send a test mail to it. Once it arrives, you should be able to retrieve it using POP or IMAP.

Posted March 18th, 2006 in category linux.