This article will show you how to configure Postfix and Dovecot to handle multiple domains stored in MySQL. Postfix Admin is used to manage the domains, mailboxes and aliases in MySQL. See How to Install Postfix Admin to setup the MySQL database that will be used by Postfix and Dovecot.
Creating the Virtual Mail User Account
Since the user names will be stored in MySQL, we will have to create a user that will be the owner for all the files belonging to the MySQL user names.
1. Create a new user, we will call it vmail. Change the Login Shell to /sbin/nologin, this user account should not be used for logging in. Learn how to use the User Manager application here.
3. Click the Groups tab and now note down the Group ID of vmail. We’ll be needing all of them later.
Configuring Postfix
host = localhost
user = postfix
password = your_password
dbname = postfix
table = domain
select_field = domain
where_field = domain
additional_conditions = and backupmx = '0' and active = '1'
postmap -q acme.com mysql:/etc/postfix/mysql-domains.cf
Replace acme.com with your own domain name. It should echo your domain.
host = localhost
user = postfix
password = your_password
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
additional_conditions = and active = '1'
result_format = %sMaildir/
postmap -q johndoe@acme.com mysql:/etc/postfix/mysql-users.cf
Replace johndoe@acme.com with your own email address. You should see the mailbox path.
host = localhost
user = postfix
password = your_password
dbname = postfix
table = alias
select_field = goto
where_field = address
additional_conditions = and active = '1'
postmap -q john@acme.com mysql:/etc/postfix/mysql-aliases.cf
Replace john@acme.com with your own alias address. You should see the destination email.
mydestination = $myhostname, localhost.$mydomain, localhost
and add the lines below
virtual_mailbox_domains = mysql:/etc/postfix/mysql-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-users.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-aliases.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:501
virtual_gid_maps = static:501
virtual_mailbox_base, virtual_uid_maps and virtual_gid_maps should contain the home directory, user id and group id of vmail respectively.
9. Restart the Postfix or MailScanner service if you have installed it. Learn how to start and stop services here.
10. You should now be able to send email to addresses found in MySQL. See Test Postfix using Telnet and try using MySQL email addresses instead of the system user names.
Configuring Dovecot
driver = mysql
connect = host=localhost dbname=postfix user=postfix password=password
default_pass_scheme = PLAIN
password_query = SELECT password FROM mailbox WHERE username = '%u'
auth_username_format = %Lu
passdb sql {
args = /etc/dovecot-mysql.conf
}
userdb static {
args = uid=501 gid=501 home=/home/vmail/%d/%n
}
uid, gid and home should contain the user id, group id and home directory respectively of the vmail user account.
Comment out all the other passdb and userdb sections except for those specified above to ensure that nothing will conflict with our MySQL virtual accounts.
4. You should now be able to login using the user names found in MySQL. See Test Dovecot using Telnet and try using MySQL user names instead of the system user names.
REFERENCE
http://www.linuxmail.info/multiple-domains-postfix-admin-centos-5/