3. Postfix installation and configuration

The default postfix package included with CentOS 5.3 is not aware of MySQL lookup tables, but includes support for SASL authentication using Cyrus-SASL libraries. A postfix + mysql + dovecot setup does not require Cyrus-SASL, but requires MySQL and/or PostgreSQL table lookup support. To correct this problem, a modified postfix package must be used. One solution is to use the CentOS Plus repository for postfix package, which supports virtual users, mysql and postgresql databases for lookups, another solution is to recompile postfix from source using a modified .spec file.

Method 1 - Postfix Installation from CentOS Plus repository, for the impatient

Method 2 - Recompile postfix package and enable MySQL and SASL support

After installing postfix using one of the methods above, it's time to get it working. It's time to disable sendmail and enable postfix, either by using 'system-switch-mail' tool, or by using chkconfig

Disable sendmail, enable postfix

# chkconfig sendmail off
# service sendmail stop
# chkconfig postfix on

The postfix process should not be started now, it's unconfigured. First, you should consider a place where to store e-mail. I've used a volume mounted on /data for mail storage in my example. It will contain a directory for each virtual domain, and each domain will contain a directory for each mailbox, like: /data/domain.tld/user1/. This directory should be created before receiving first message. Postfix will create automatically the rest of the path (./domain/user), but only when the first message for the user arrives. If dovecot won't be able to access user's home directory, the e-mail client will display an error, even if the username and password are correct.

Create the mail store

# mkdir /mail
# chown postfix:postfix /mail


You should change the following parameters on /etc/postfix/main.cf:

/etc/postfix/main.cf modifications

# myhostname should be set to the DNS name of the server
myhostname = mx1.mydomain.tld
mydomain = mydomain.tld
myorigin = $mydomain
# listen for connections on all interfaces
inet_interfaces = all
# mail is stored in maildir format in the home directory of each user
home_mailbox = Maildir/
# Virtual users configuration
virtual_relay_domains_maps = mysql:/etc/postfix/mysql_relay_domains_maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_transport = virtual
virtual_mailbox_base = /mail
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
# 89 is the default UID of postfix user on CentOS systems,
# it will be used for virtual accounts too

virtual_minimum_uid = 89
virtual_uid_maps = static:89
virtual_gid_maps = static:89
smtpd_sasl_auth_enable = yes
# indicate postfix that we use dovecot SASL instead cyrus-sasl
smtpd_sasl_type = dovecot
smtpd_sasl_authenticated_header = yes
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

Enable automatic startup of postfix process:

Enable postfix automatic startup

# chkconfig postfix on
# service postfix start


Up: CentOS Mail Server setup: Postfix, Dovecot, MySQL, SASL, Postfixadmin, TLS
Prev: Dovecot installation and configuration
Next: Postfix TLS configuration
Comments