Complete Virtual Mail Server/Postfix to Database/ru

Установка postfix
Postfix installation is quite straight forward. A basic installation instruction for Postfix should be followed.

Подключение postfix
После того как очень минимальная настройка postfix была произведена, настало время подключить его к базе данных.

PostgreSQL
Необходим пользователь в базе данных для осуществления запросов:

Также пользователю postfix необходимы некоторые разрешения, чтобы производить операции над таблицами:

MySQL
If MySQL is used instead of PostgreSQL then follow the following instructions. Fetch the SQL dump and save it as as it will be needed soon.

Сперва установите MySQL:

Создайте начальную базу данных:

Follow the on-screen instructions for adding a root password within MySQL as otherwise the database will be wide open.

Запустите сервер базы данных MySQL и создайте базу данных с именем :

Запустите клиент, чтобы предоставить соответствующие права к базе данных :

Проверьте, что новый пользователь может подключиться к серверу mysql:

The new database has default values and tables set up for two domains. The following tables are included:


 * alias - local email alias and mailman alias information.
 * relocated - relocated user email address maps
 * transport - default mail transport information for all domains you are hosting
 * users - all user account information
 * virtual - virtual domain email alias maps

The values of the  uid and gid should be those of the   user and group.

Querying
All these queries are tested on the database to ensure the queries are written properly. This does require however that the database has been filled to be useful. When postfixadmin is used, this can be done easily from the UI. Otherwise, simple SQL queries need to be written and executed.

PostgreSQL
Linking postfix to a database isn't that special, postfix just executes predefined SQL routines. These SQL queries will be stored in a file per query in a directory.

Be aware that any errors in the configuration information in these files can be pretty tricky to track down. Be meticulous with both the contents of the files and their names. Many errors in these files will be announced in the mail log such as "user example@example.com doesn't exist" without any further explanation.

It's best to test the query on the database (using copy paste) to ensure no typo's exist in the query:

Also here, it's best again to execute the query on the database:

Run the query on the database to verify its output:

MySQL
Set up the necessary configurations for postfix to interact with the database for all its other transport needs. Remember to replace each value with the name of the proper user, user id, password, alias, email address, and so on.

Права доступа
Только postfix должен иметь доступ к этим файлам, так как они содержат пароли:

MySQL/MariaDB
As of Postfix 2.0.x, there were a number of significant changes over the 1.1.x release. Notably the transport, virtual-gid, and virtual-uid tables are no longer necessary. The tables are still included to support potential different use cases.

Проверка подключения к базе данных
Postfix needs to be restarted to have it connect to the database:

Check for any problems in, such as incorrect permissions.

Using telnet, the mailserver can be tested again to check whether the database is properly used: