Thanks a lot for this quick tutorial.
I have a suggestion to make:
Personally, at first, I did not use aliases. Therefore, I ended up with relay_recipients containing the same entries several times, as they just ended up being appended at the end of the file.
My understanding is that the relay_recipients file is first overwritten using aliases, and only then will the actual mailboxes be appended.
It is better to first look for mailboxes, and only then for the aliases, for the following reasons:
- It seems more logical (but I admit that could just be a point of view!
- A mailbox needs to exist first for an alias to be created
- Mailboxes are repeated at the end of the file if no alias is configured in ISPConfig (but we already know that).
The code should therefore become:
// file /etc/postfix/map_relay.php
$link = mysql_connect('s0.ikfsystems.sk', 'map_relay', 'RRhQe8qa4Qhmezeq', false, MYSQL_CLIENT_SSL);
$result = mysql_query('SELECT `domain` FROM `mail_domain` WHERE `active` = "y"');
create_map($result, 'domain', '/etc/postfix/relay_domains');
$result = mysql_query('SELECT `email` FROM `mail_user` WHERE `disabledeliver` = "n"');
create_map($result, 'email', '/etc/postfix/relay_recipients');
$result = mysql_query('SELECT `source` FROM `mail_forwarding` WHERE `active` = "y"');
create_map($result, 'source', '/etc/postfix/relay_recipients', 'a');
exec('/usr/sbin/postmap hash:/etc/postfix/relay_domains & /usr/sbin/postmap hash:/etc/postfix/relay_recipients');
function create_map($result, $key, $file, $type = 'w')
if(mysql_num_rows($result) == 0)return false;
$content = '';
while($row = mysql_fetch_array($result))
$content .= $row[$key]."\tOK\n";
write_file($file, $content, $type);
function write_file($file, $content, $type = 'w')
$handle = fopen($file, $type);