Skip to content

V2 Postfix and MySQL Integration

Barry O'Donovan edited this page Feb 11, 2014 · 1 revision

Applies to ViMbAdmin v2 only! Deprecated in favour of ViMbAdmin v3.


ViMbAdmin is intended to be integrated with an MTA (and a IMAP / POP3 daemon) via SQL lookups. This document explains how to integrate ViMbAdmin on MySQL with Postfix. The instructions should be similar for other database backends.

Requirements

You must ensure that Postfix has been built with MySQL support or install the necessary package on various platforms. For example:

  • on Debian / Ubuntu, install postfix-mysql;
  • on FreeBSD, build with MySQL support;
  • on CentOS / RedHat, install the version of Postfix from the CentOS Plus repository.

Configure Postfix

Postfix itself needs to be configured to using mappings via MySQL for various elements. An example configuration might be the following which uses MySQL to map aliases, domains and mailboxes - exactly what ViMbAdmin manages:

virtual_alias_maps = mysql:/etc/postfix/mysql/virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql/virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql/virtual_mailbox_maps.cf

Other elements you might also want to extract from ViMbAdmin are the UID and GID of the mailboxes and the base directory. I statically set those on my test box as follows:

virtual_minimum_uid = 2000
virtual_uid_maps = static:2000
virtual_gid_maps = static:2000
virtual_mailbox_base = /mnt/mail

ViMbAdmin supports all of the above also and you can use equivalent MySQL maps for them if you wish.

Configure the MySQL Map Files

We reference three files above. The following are example contents for ViMbAdmin:

/etc/postfix/mysql/virtual_alias_maps.cf

For Postfix < 2.2:

user = vimbadmin
password = password
hosts = 127.0.0.1
dbname = vimbadmin
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'

Postfix 2.2. and later has a new query parameter allowing the more compact:

user = vimbadmin
password = password
hosts = 127.0.0.1
dbname = vimbadmin
query = SELECT goto FROM alias WHERE address = '%s' AND active = '1'

The following examples are show for Postfix >= 2.2.

/etc/postfix/mysql/virtual_domains_maps.cf

user = vimbadmin
password = password
hosts = 127.0.0.1
dbname = vimbadmin
query = SELECT domain FROM domain WHERE domain = '%s' AND backupmx = '0' AND active = '1'

/etc/postfix/mysql/virtual_mailbox_maps.cf

user = vimbadmin
password = password
hosts = 127.0.0.1
dbname = vimbadmin
query = SELECT maildir FROM mailbox WHERE username = '%s' AND active = '1'