postfix transport with smarthost

Dear lazyyweb,

Has anyone got a way for postfix to use a transport map such that it sends email to the given MX host for some specified domains then default to a smarthost for the remainder?

The logic would be:

IF domain in (‘’, ‘’,etc etc) THEN use the relevant MX host ELSE send to

i can use a transport map to send from specific domains to specific hosts, eg goes to mailserver but not to just use’s MX hosts

Enhanced by Zemanta


13 responses to “postfix transport with smarthost”

  1. Is it not enough to simply put that in a transport table (null nexthop, use the recipient domain, cf. transport(5)): smtp:

    Otherwise, you can use no relayhost but instead use a transport table that uses your relay as a nexthop for all except some domains:
    * :relayhost.example :

    This is almost the same as an example that is provided in transport(5).

    1. This worked! You cannot use relayhost because the transport map is no longer used and everything goes via it. However a wildcard does work with specified domains using their MX hosts and everything else going via relay host. Thanks.

  2. Please read the postfix docs, they’re there for a reason.

    Any entry in the transport map will be resolved for its MX addresses if specified without [], or resolved for its A addresses if specified within [].

    Manpage transport(8) even shows how to do what you want in the examples.

  3. Michael Avatar

    Are you possibly using the [host] form? As transport(5) says, [host] vs. host disables MX lookups:

    “The interpretation of the nexthop field is transport dependent. In the case of SMTP, specify a service on a non-default port as host:service, and disable MX (mail exchanger) DNS lookups with [host] or [host]:port. The [] form is required when you specify an IP address instead of a hostname.”

  4. Its easy. As you say you have to use the transports map. If you put a domain/host as the transport, postfix will query for it’s mx record by default. In fact, if you want to prevent this behaviour you have to enter the transport between square brackets, as in []

  5. Sounds like you want to use something like this:
    transport_maps = hash:/etc/postfix/transport
    relayhost =


    1. relayhost trumps the transport map so everything goes via the relay.

  6. Kevin Locke Avatar
    Kevin Locke

    Does it need to be done with a transport map? It sounds like using sender_dependent_relayhost_maps would accomplish what you are looking for (just set relayhost to the default smarthost and add each @domain with a different smarthost to the relayhost map).

  7. $ man 5 transport

    In order to deliver internal mail directly, while using a mail relay for all other mail, specify a null entry for internal destinations (do not change the delivery transport or the nexthop information) and specify a wildcard for all other destinations.

    my.domain :
    .my.domain :

    1. oh ok, i didnt realse wildcards like that work, or the ultimate wildcard

  8. Russ Allbery Avatar
    Russ Allbery

    In the transport map, a value of “:” says to use the default routing, which means to use the MX records. Example from my transport map: : :

Leave a Reply

Your email address will not be published. Required fields are marked *