Postfix Relay Based on Sender Recepient

Discussion in 'Server Operation' started by Contertulio, Jan 5, 2017.

  1. Contertulio

    Contertulio New Member

    What is the best practice when one has to implement this sort of ruleset in postfix:

    • Email sent from local domain1.com, domain2.com to example.com, example1.com ought to be relayed to smtp.external.com.
    • Email sent to everyone else @example.com and example1.com ought to be relayed locally

    I know there is a way to do a relay filtering recipient address using transport_maps, but I do not know how to filter depending on the sender address too.

    Can you help me please?? Thanks in advance
     
  2. florian030

    florian030 ISPConfig Developer ISPConfig Developer

    Add sender_dependent_relayhost_maps = hash:/etc/postfix/relayhost_map to postfix, create /etc/postfix/relayhost_map:
    @example.com [relay.server.com]
    someone@example2.com [relay.server.com]

    and postmap this file. Afterwards reload postfix.
    Every mail sent from @example.com will be relayed to relay.server.com
     
    Contertulio likes this.
  3. Contertulio

    Contertulio New Member

    Thank you very much for your answer. But this only filters out sender emails.
    In my case I want to relay from @domain1.com to @example1.com only. All other conditions are filtered locally.
     
  4. florian030

    florian030 ISPConfig Developer ISPConfig Developer

    transport_maps = hash:/etc/postfix/transport

    /etc/postfix/transport:
    recipient-domain smtp:[relay.com]

    postmap /etc/postfix/transport

    postfix reload
     
    Contertulio likes this.
  5. Contertulio

    Contertulio New Member

    So the following would work as I comment?
    - Messages from user@domain1.com to user@example1.com => Using relay.server.com
    - Rest of messages from user@domain1.com to other domains => Using localhost
    - Messages from user@domain2.com => Using localhost

    /etc/postfix/relayhost_map
    @domain1.com [relay.server.com]

    /etc/postfix/transport:
    @example1.com smtp:[relay.server.com]

    postmap /etc/postfix/relayhost_map
    postmap /etc/postfix/transport
    postfix reload
     

Share This Page