How to have Postfix send email to another server if user lookup fails for specific domains

postfixsmtp

Currently my server acts as a gateway, checks AD for valid email addresses, if the email address exists in exchange it sends over the email, otherwise just rejects (typical)

I need Postfix to send any emails with specific domains to other servers (not same network).

Steps would go something like this:

get requested email
check if email exists in AD
if it doesn't exist, check if the domain is in a file and send that email to a server specified in that file

Is this even possible? I looked at smtp_fallback_relay but the second email is checked, it get rejected if not found in AD

Best Answer

Postfix will verify validity before any routing is performed, so that order must be respected.

Put your valid recipient lists for exchange and the other destinations in one of the appropriate maps, and then put both in sequential transport_maps; you can make it not change the routing by just specifying joe@foo.bar smtp: as the RHS.