Postfix + MySQL on CentOS
Some things might not be right, but this is what worked for me, so if it doesn't work for you, sorry but this is how I did it, and it works. There are many many many links to doing this, so if this doesnt work keep searching.
For this I started with a clean CentOS install, it was CentOS 5.4. During the CentOS install I used the advanced package options and I selected squirrelmail, httpd(web server), mysql, and I unchoose sendmail, it still installed sendmail.
After the machine is booted and updated we then want to setup the mysql database and user.
/etc/init.d/mysqld start
mysql -u root -p
Password: ***************************************** (not really my password, but you get the idea
mysql> create database postfix
Query OK, 1 row affected (0.00 sec)
mysql> grant all on postfix.* to 'postfixuser'@'localhost' identified by 'MySuperSecurePassword!';
Query OK, 0 rows affected (0.00 sec)
now we want to add the postfix packages.
/etc/init.d/sendmail stop
yum remove sendmail
yum install php-mysql spamassassin php php-mbstring postfix
Postfix should now be installed, but it is missing some things.
[root@localhost ~]# postconf -m
btree
cidr
environ
hash
ldap
nis
pcre
proxy
regexp
static
unix
If you notice, there is not MySQL support in there. That is in a special package in the CentOS Plus repo.
wget http://mirror.centos.org/centos-5/5.4/centosplus/i386/RPMS/postfix-2.3.3-2.el5.centos.mysql_pgsql.i386.rpm
When you do the rpm install it will tell you that you need postgressql, i just installed it and made sure it was off and the service was off.
yum install postgresql
When you install postfix from the RPM it will tell you that you have a newer version on your system, and that is why we are using the --force
rpm -U postfix-2.3.3-2.el5.centos.mysql_pgsql.i386.rpm --force
Restart the server/service then run the postconf -m again to verify the MySQL support
[root@localhost ~]# postconf -m
btree
cidr
environ
hash
ldap
mysql
nis
pcre
pgsql
proxy
regexp
static
unix
Next we want to add Postfix Admin, there is no RPM for this, but it is a simple web application that will setup the tables in the database for you.
http://sourceforge.net/projects/postfixadmin/
Because this is going to be a straight mail server, I just untared it in the /var/www/html directory and set it up from there. This is a nice utility for managing and maintaining users, and you can create admins per domain so that they can manage their own accounts.
connect to the server at the postfix admin URL and configure that, it will allow you to configure the databases even though we haven't setup postfix to use the databases yet.
After you have postfix admin configured it is time to add the magic to the postfix/main.cf file.
You want to change it to allow users
Be sure to find the corisponding lines here and comment them out or change them in the main.cf
#MySQL DB properties
# This is for the virtual users
virtual_alias_maps = mysql:/etc/postfix/virtual_alias_maps.cf
# the group id that postfix runs as
virtual_gid_maps = static:89
# Create this directory and chmod -R postfix:postfix /home/vmail
virtual_mailbox_base = /home/vmail
# this will be the domains that are allowed to send/receive on the box
virtual_mailbox_domains = mysql:/etc/postfix/virtual_domains_maps.cf
# mailboxes
virtual_mailbox_maps = mysql:/etc/postfix/virtual_mailbox_maps.cf
# more user and groupIDs
virtual_minimum_uid = 89
virtual_mailbox_uid = 89
# we want the transport type to be virtual instead of physical
virtual_transport = virtual
virtual_uid_maps = static:89
And the Database connections
cat virtual_alias_maps.cf
user = postfixdatabaseuser
password = password
host = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
cat virtual_alias_maps.cf
user = postfixdatabaseuser
password = password
host = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address
cat virtual_domains_maps.cf
user = postfixdatabaseuser
password = password
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain
Restart the postfix server, add to local users with postfix admin, and use squirrelmail to verify that you can send and receive emails.
Again this is a general overview, email me if you have any questions.
Edits might be made to this as time goes on as well.