Postfix + MySQL
Index:
Disclaimer
Postfix install
main.cf
Config files
MySQL setup
Table explanation
The \transport\ table
The \aliases\ table
the \remote_aliases\ table
Additional notes
Disclaimer:
This HOWTO is based on the assumption that you have a good deal of knowledge of Postfix and MySQL.
The howto is based on the latest snapshot of postfix (20010808).
The virtual agent is not in the stable version of postfix yet.
Furthermore you need to have read MYSQL_README and VIRTUAL_README (snapshot only)
and basicly everything else there is to read.
This is a step by step HOWTO of how to setup the virtual part of postfix.
Postfix install:
Unpack postfix.
Do (inside the postfix directory):
make -f Makefile.init makefiles \
\CCARGS=-DHAS_MYSQL -I/some/where/mysql/include\ \
\AUXLIBS=/some/where/mysql/lib -lmysqlclient -lz -lm\
make && make install
cp the virtual bin from the virtual directory into the postfix directory. ie: cp src/virtual/virtual /usr/libexec/postfix
Replace the \/some/where/\ with your system\s path.
Now setup Postfix as you usually would, but almost all the mapping is
done through MySQL.
main.cf:
transport_maps = mysql:/etc/postfix/transport.cf
virtual_mailbox_base = /data/mail
virtual_uid_maps = mysql:/etc/postfix/ids.cf
virtual_gid_maps = mysql:/etc/postfix/ids.cf
virtual_mailbox_maps = mysql:/etc/postfix/aliases.cf
virtual_maps = mysql:/etc/postfix/remote_aliases.cf
Config files:
transport.cf:
user = postfix
password = postfix
dbname = mail
table = transport
select_field = transport
where_field = domain
hosts = localhost
ids.cf:
user = postfix
password = postfix
dbname = mail
table = aliases
select_field = id
where_field = alias
hosts = localhost
aliases.cf:
user = postfix
password = postfix
dbname = mail
table = aliases
select_field = maildir
where_field = alias
hosts = localhost
remote_aliases.cf:
user = postfix
password = postfix
dbname = mail
table = remote_aliases
select_field = rcpt
where_field = alias
hosts = localhost
Also remember that relay_domains needs to contain $transport_maps to lookup local virtual domains.
alias_maps does not affect the virtual agent.
MySQL Setup:
Create a mysql user/database for postfix:
gaia:~# mysql
mysql> use mysql;
mysql> insert into user (Host, User, Password) values(\localhost\,\postfix\, password(\postfix\));
mysql> insert into db (Host, Db, User, Select_priv) values(\localhost\,\mail\,\postfix\,\Y\);
mysql> create database mail;
Create the tables needed:
mysql> use mail;
mysql> create table transport (domain varchar(255) PRIMARY KEY, transport char(8));
mysql> create table aliases (id int(6), alias varchar(255) PRIMARY KEY, maildir varchar(255));
mysql> create table remote_aliases (alias varchar(255) PRIMARY KEY, rcpt varchar(255));
Finish off by reloading the mysql server:
gaia:~# mysqladmin reload
Table explanation:
The \transport\ table (from the man page):
The optional transport table specifies a mapping from
domain hierarchies to message delivery transports and/or
relay hosts. The mapping is used by the trivial-rewrite(8)
daemon.
Example:
mysql> select * from transport;
+-----------+-----------+
| domain | transport |
+-----------+-----------+
| gostil.dk | virtual: |
+-----------+-----------+
The \aliases\ table:
This table is used for 2 things:
1: Map aliases to mailboxes / maildirs.
2: Map uid/gids to mailboxes.
Example:
mysql> select * from aliases;
+------+---------------+------------------------+
| id | alias | maildir |
+------+---------------+------------------------+
| 1002 | dvp@gostil.dk | gostil.dk/dvp/Maildir/ |
+------+---------------+------------------------+
The \remote_aliases\ table:
This final table is used to map aliases at one domain
to aliases at another domain.
Example:
mysql> select * from remote_aliases;
+----------------+----------------+
| alias | rcpt |
+----------------+----------------+
| test@gostil.dk | daniel@rtfm.dk |
+----------------+----------------+
[/pre]
Additional Notes:
The base directory needs to be owned by whichever user
you chose when installing postfix (in my case, maildrop).
The permissions need to be 0700.
When the first mail is sent to one of your aliases the rest is
auto magically created by Postfix.
원본 출처 : http://kummefryser.dk/HOWTO/mail/postfix_mysql.html
|