Postfix MX lookup for delivery instead of local delivery for specific domains

postfix

Before I clarify my question I need to explain the current setup.

We've got 1 Postfix server that can receive mail and store it in a mailbox. Some clients of ours have their own Exchange server, but we still provide a POP3 box on our Postfix server. The DNS of their domain is setup to first try to deliver mail to the Exchange server, if that one can't be reached deliver it to our Postfix server. If mail is being delivered to the Postfix server the mail gets stored inside a POP3 account. When the Exchange server is back online again it uses the POP-Locator to read the contents of the POP3 mailbox, download the mails and distribute them among the mailboxes on the Exchange server.

This all works very well. Because during an outage clients can still logon to our webmail and read important mail. This is a feature we'd like to keep.

The problem however is, that most clients also host their website on the same server that runs Postfix. When software running on that server tries to deliver mail to one of the clients email addresses it delivers it locally. What we want is Postfix to use MX lookup to see to which server the mail should be delivered.

For a long time now I've been trying to figure out to do this. I have the Postfix book and read through it. Looked up many configuration examples and other resources on the internet.

So far I've been trying to use transport_maps = hash:/etc/postfix/transport and list the specific domains in there, run postmap to regenerate the lookup tables and do a postfix reload. Whatever I try to do mail is being delivered locally.

To add some more context, we use Courier and have listed all domains in virtual_alias_maps = hash:/etc/postfix/virtual.

Any help would be much appreciated.


/etc/postfix/transport

example.com    smtp

/etc/postfix/virtual

example.com    postmaster
@example.com   someuseraccount

Best Answer

The reason that you're finding it hard to do is that it is essentially impossible, because it contradicts the MTS model employed by Postfix. Mailboxes are either local or remote; they cannot be both. The local machine either is the final destination for the mail or it is not. Local and virtual domain address classes are "final destination", remote domain ("relay"/"default") address classes are not. The final destination for a single mailbox cannot be both a maildir on the local machine or a remote transport to some other machine. It has to be one or the other. A domain is either a local/hosted one, in which case mail for mailboxes in that domain is delivered to the local maildir to be picked up by POP3, or a remote one, in which case mail for mailboxes in that domain is transported to another machine and not delivered locally.

Your only real option is to run two separate MTSes — two distinct instances of Postfix. One provides SMTP Relay service to the Internet at large, and is configured with the domains in question as virtual domains, locally hosted, with all mail delivered to the maildir for subsequent retrieval via POP3. The other provides sendmail, postdrop, and the local SMTP Submission service, and is configured with the domains in question as relay domains, remotely hosted, whose mail is to be transported to the Exchange server.

Précis: Having two distinct and contradictory "paper paths" for mail requires having two MTS instances.

Related Topic