This page describes the configuration of domains utilising the relay transport
By setting the transport type for a domain to relay, this config allows a domain to relay mail to elsewhere - I use it to provide some management and filtering for customer's mails before forwarding them on to the customer's own mail server. It draws heavily on the original config described in POSTFIX_CONF.txt (/usr/share/doc/postfixadmin/DOCUMENTS/POSTFIX_CONF.txt.gz in Debian systems)
The config described was done on a system running Debian Squeeze, it should work with other distributions without major adjustments.
Rather than add an addition database field, with the coding required to handle that, for this setup I've used the description field to hold the relay destination. This can be an IP address or FQDN.
To use from the Postfix Admin interface, set the transport to relay and put the destination in the description field for the domain. Then create an alias for each address to be relayed. Alias domains are supported, as for virtual domains, as are wildcard aliases.
If using alias domains, both domains must be set to relay, both domains must be set to active, and the domain alias must be set to active.
If not already set (it should be by default), make sure "relay" is included in the list of available transports
$CONF['transport_options'] = array (
'virtual', // for virtual accounts
'local', // for system accounts
'relay' // for backup mx
);
If you have already configured virtual support as described in [[Courier configuration]] then we'll need to modify some of the SQL files from that, this is the complete list of files from my setup.
For my setup, I added an additional user (postfix-ro) which only has read-only access to the database (it needs SELECT and LOCK TABLES privileges). None of these map lookups need write access and it makes things more secure. I also have the database running on a separate backend machine that serves several mail handlers.
You'll need to set the user, password, and host in these map files to suit your setup.
/etc/postfix/sql/mysql_relay_domains_maps.cf
user = postfix-ro
password = password
hosts = host
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' and transport = 'relay' and active = 1 AND NOT exists (select * from alias_domain where alias_domain = '%s' AND alias_domain.active = '1')
/etc/postfix/sql/mysql_relay_alias_domains_maps.cf
user = postfix-ro
password = password
hosts = host
dbname = postfix
query = SELECT a.domain FROM domain a, domain t, alias_domain WHERE a.domain='%s' AND a.transport = 'relay' AND a.active = '1' AND alias_domain.alias_domain = a.domain AND alias_domain.active = '1' AND t.domain = alias_domain.target_domain AND t.transport = 'relay' AND t.active = '1'
These two files provide lookups for relays we are prepared to relay mail to.
/etc/postfix/sql/mysql_relay_transports.cf
user = postfix-ro
password = password
hosts = host
dbname = postfix
query = SELECT concat('relay:[',description,']') FROM domain WHERE domain='%s' and transport = 'relay' and active = 1
Provides Postfix with the transport & destination to use for the domain.
/etc/postfix/sql/mysql_alias_maps.cf
user = postfix-ro
password = password
hosts = host
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'
#expansion_limit = 100
/etc/postfix/sql/mysql_alias_domain_maps.cf
user = postfix-ro
password = password
hosts = host
dbname = postfix
query = SELECT goto FROM alias,alias_domain,domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1' AND domain.domain = alias_domain.target_domain and domain.active = '1'
/etc/postfix/sql/mysql_alias_domain_catchall_maps.cf
user = postfix-ro
password = password
hosts = host
dbname = postfix
query = SELECT goto FROM alias,alias_domain,domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1' AND domain.domain = alias_domain.target_domain and domain.active = '1'
These are derived from the mysql_virtual_* files described in POSTFIX_CONF.txt and are shared between both relay domain and virtual domain handling. The define the list of addresses to relay mail for.
We need to add a map lookup for relay transports, this assumes you already have Vacation support configured. Then we add maps for the domains to relay for, and the addresses within those domains. See [http://www.postfix.org/postconf.5.html Postfix Configuration Parameters] for details.
transport_maps = hash:/etc/postfix/transport,
mysql:/etc/postfix/sql/mysql_relay_transports.cf
relay_domains = mysql:/etc/postfix/sql/mysql_relay_domains_maps.cf,
mysql:/etc/postfix/sql/mysql_relay_alias_domains_maps.cf
relay_recipient_maps =
mysql:/etc/postfix/sql/mysql_alias_maps.cf,
mysql:/etc/postfix/sql/mysql_alias_domain_maps.cf,
mysql:/etc/postfix/sql/mysql_alias_domain_catchall_maps.cf
The virtual_* map statements will need editing to suit the new file names
virtual_alias_maps =
mysql:/etc/postfix/sql/mysql_alias_maps.cf,
mysql:/etc/postfix/sql/mysql_alias_domain_maps.cf,
mysql:/etc/postfix/sql/mysql_alias_domain_catchall_maps.cf
virtual_mailbox_domains =
mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf,
mysql:/etc/postfix/sql/mysql_virtual_alias_domains_maps.cf