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 (‘example.net’, ‘foo.bar’,etc etc) THEN use the relevant MX host ELSE send to smarthost.isp.net

i can use a transport map to send from specific domains to specific hosts, eg @domain.com goes to otherisp.net mailserver but not to just use domain.com’s MX hosts

Enhanced by Zemanta

Comments

13 responses to “postfix transport with smarthost”

  1. Elessar Avatar

    Is it not enough to simply put that in a transport table (null nexthop, use the recipient domain, cf. transport(5)):
    example.net 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
    example.net :

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

    1. Craig Avatar
      Craig

      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. Anonymous Avatar

    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
    Michael

    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. marcos Avatar
    marcos

    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 [myrelay.example.com]

  5. kbo Avatar
    kbo

    Sounds like you want to use something like this:

    main.cf:
    transport_maps = hash:/etc/postfix/transport
    relayhost = default.relay.com

    transport:
    somedomain.org relay:relay.for.somedomain.com
    otherdomain.org relay:another.relay.org

    1. Craig Avatar
      Craig

      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. tonton Avatar

    $ 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 :
    * smtp:outbound-relay.my.domain

    1. Craig Avatar
      Craig

      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:

    stanford.edu :
    .stanford.edu :
    alumni.stanford.edu smtp:smtp.stanford.edu
    law.stanford.edu smtp:smtp.stanford.edu
    sls.stanford.edu smtp:smtp.stanford.edu
    * smtp:smtp.stanford.edu

Leave a Reply

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