We have a multi-tenant email relay set up that has a transport map file that looks like this:
domain1.com smtp:mail.domain1.com
domain2.com smtp:mail.domain2.com
domain3.com smtp:mail.domain3.com
[etc]
In the event mail.domain1.com is down, email for domain1.com will be held by the postfix server until mail.domain1.com starts responding again. However we have a customer who has a backup DSL line on their site, an their email server is also available over this. How can I tell the transport to failover to a different host if the first is unavailable?
Clarification I think there is some confusion over the purpose of this setup. This postfix server is an inbound mail relay for clients who do not have AV and Spam protection on site. It is one of a pair, which are configured as the 2 MX records for these customers. They receive and clean email before forwarding it on to their local mail servers, as well as acting as a buffer in case of an outage on their end. These customers don't generally have multiple on site mail servers, they are too small hence this service. What they do often have though is a secondary connection, eg fibre and DSL, so I'd like to be able to direct the onward SMTP to their second connection should the first be unreachable.
You can add a failover server declaring a new MX DNS record pointing to the failover IP (I guess the server external IP will change if it's NATed behind a DSL line).
The new MX record will have a lower weight value that the default MX record, which will prevent from using it when the default/main server is reachable
The first question is WHY.
If your DNS is properly set up, relaying mail for example.com via mail.example.com is automatic; this is how it's supposed to work.
WHY are you circumventing the normal flow of email ?
If the answer is "because we cannot use DNS", then there should be no hostnames in your transport_maps at all; use bracketed IP literals:
As to the failover part: provided the list of relay domains is not large, you could set name resolution to "native" and put multiple IPs in the /etc/hosts file: