How to – Postfix MySQL

Configuration details:-

 + CentOS 5

+ MySQL 5

+ Postfix 2.5


1. Download the latest Postfix from http://www.postfix.org/download.html

 2. Untar the file run make command. Do as the following:-

# make -f Makefile.init makefiles ‘CCARGS=-DHAS_MYSQL -I/usr /include/mysql’ ‘AUXLIBS=-L/usr/lib/mysql -lmysqlclient -lz -lm’
# make install

3. Now to configure Postfix to lookup for aliases in MySQL database

# vi main.cf

Search the following line and change value to:

alias_maps = mysql:/etc/postfix/mysql-aliases.cf

4. Now create a new file named mysql-aliases.cf in default Postfix configuration directory. Usually in /etc/postfix

# vi mysq-aliases.cf

Add the followings:

# mysql config file for local aliases lookup
# The user name and password to log into the mysql server.
user = <database username>
password = <database user password>
# The database name on the servers.
dbname = <database name>
# For Postfix 2.2 and later The SQL query template.
query = SELECT forw_addr FROM mxaliases WHERE alias=”%s”;

5. Restart your postfix

# postfix stop
# postfix start

Optional : You can also configure your Postfix to lookup for local recipients using MySQL database. Below is the example for database lookup and configuration with DBMail

 6. Create a new file named sql-recipients.cf in Postfix configuration directory

# vi sql-recipients.cf

Add the following:

user = <username>
password = <password>
hosts = <dbhost>
dbname = <dbname>
query = SELECT alias FROM dbmail_aliases WHERE alias=’%s’
UNION SELECT userid FROM dbmail_users WHERE userid=’%s’;

7. Configure your main.cf to map to the sql-recipients.cf file:

# vi main.cf

Look for local_recipient_maps and add the following value:

local_recipient_maps = mysql:/etc/postfix/sql-recipients.cf

8. Restart your postfix

# postfix stop
# postfix start

 Reference Site:

DBMail with Postfix : http://www.dbmail.org/dokuwiki/doku.php?id=setup_postfix
Postfix MySQL : http://www.postfix.org/MYSQL_README.html

~ by ucishark1978 on June 21, 2008.

Leave a Reply