How to Configure Postfix for Specific Domain Mail Delivery

postfix

We currently have postfix handling emails generated by a number of apps. A number of these emails are destined for users inside the organisation, whose mail is on an Exchange server in the same site as the postfix box.

I'm looking for a way to do this, but my Google-fu is letting me down:

If the recipient domain is one of our domains, deliver the mail to host mail.example.com. All other mail is delivered by looking up the MX record/s and processing normally.

Edit: to clarify, the apps generating the emails are sending to users outside of our organisation too, postfix is not receiving mail at all.

Best Answer

Instructions work for Ubuntu, you may need to adjust for other distros.

Add the following to /etc/postfix/main.cf:

relay_domains = domain1.com, domain2.com
transport_maps = hash:/etc/postfix/transport
relay_recipient_maps = hash:/etc/postfix/relay_recipients
relay_transport = relay

Create the file /etc/postfix/transport:

domain1.com  smtp:[mail.example.com]
domain2.com  smtp:[mail.example.com]

Create the file /etc/postfix/relay_recipients:

@domain1.com x
@domain2.com x

Run these commands:

$ sudo postmap /etc/postfix/transport
$ sudo postmap /etc/postfix/relay_recipients
$ sudo /etc/init.d/postfix reload
Related Topic