1

Topic: [FAQ] How to relay your mails per-domain or per-user (LDAP solution)

This tutorial is used to explain how to set per-domain or per-user mail relay with iRedMail. If they don't work for you, please post a new topic in iRedMail General Technical Support forum.

Note: iRedMail supports per-domain and per-user mail relay since 0.5.0.
Solution: Relay all mails for one domain to another mail server

There are two solutions for per-domain mail relay.

1) Host this mail domain as backup mx.

a) To let postfix know this, you have to set 'domainBackupMX=yes' of your mail domain in LDAP.
b) Comment 'relay_recipient_maps' in postfix /etc/postfix/main.cf if you don't have mail accounts of this domain in your LDAP server.

#relay_recipient_maps = proxy:ldap:/etc/postfix/ldap_virtual_mailbox_maps.cf

c) Set proper 'mtaTransport' of your mail domain in LDAP.

If you want to relay all mails to another server which has domain name 'destination.com', you should set it to:

mtaTransport: smtp:destination:25

Postfix will query DNS server and get ip address of MX record of 'destination.com'.
If you want to use A record instead of MX record, you should set transport to:

mtaTransport: smtp:[destination]:25
Solution: Relay all mails for one user to another mail server

Just set 'mtaTransport' of this mail user to proper value like per-domain setting, no addition settings are required.

Background

iRedMail uses local command ('deliver' program, which provided by dovecot) to deliver all mails by default. But how does postfix know this?

Because we have below settings:

1) We have 'dovecot' entry in postfix config, in file /etc/postfix/master.cf:

dovecot unix    -       n       n       -       -      pipe
  flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient} -f ${sender}

Here, 'dovecot' is transport name, not name of some executeable program.

2) We expect Postfix use 'dovecot' transport to deliver all mails for this domain, it's set in domain preferences which stored in LDAP, like this:

dn: domainName=a.cn,o=domains,dc=iredmail,dc=org
objectClass: mailDomain
domainName: a.cn
mtaTransport: dovecot             # <- This one. Do you see me?
accountStatus: active
enabledService: mail
enabledService: senderbcc
enabledService: recipientbcc

Here, we have 'mtaTransport=dovecot', 'dovecot' is transport name we mentioned in 1).

3) Postfix will lookup transport name with LDAP query, it's set in postfix (/etc/postfix/main.cf):

transport_maps = 
    proxy:ldap:/etc/postfix/ldap_transport_maps_user.cf,
    proxy:ldap:/etc/postfix/ldap_transport_maps_domain.cf

As you see, postfix will query per-user transport program first, if not set, it will query per-domain transport program.

4) Postfix will invoke command and arguments which set for this transport name after it get transport name with LDAP query.

As you see, command and arguments are set in postfix /etc/postfix/master.cf which we already mentioned in 1).

Not only local command are allowed in transport, you can relay mails with different transport setting. For more examples, please refer to postfix manual - transport(5).

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.