Setup Mail Relay on postfix based on recepient domain

You will need to do all of this as root, so either sudo or elevate to a root shell.

  1. Create a file that will contain the domains that will be processed by another server. I used /etc/postfix/bysender.
  2. Open the file bysender, add the following information:
    @example.com   [outbound.thirdparty.server.com]
    
    • On the left @example.com is the domain that you want to have its messages forwarded (relayed) to the outside server
    • The right [outbound.thirdparty.server.com] is the server that you want to relay messages to, and yes you need the brackets
    • By the way: You could have one particular user’s messages relayed to a different outside mail server by just putting in the entire e-mail address on the left side
  3. Save and Close the bysender file.
  4. Now we need to hash/map the bysender file so that Postfix can use it. Run the following command:
    postmap /etc/postfix/bysender
  5. Now open your Postfix main.cf and insert the following:
    sender_dependent_relayhost_maps = hash:/etc/postfix/bysender
    
    • Update the file path if needed
  6. Now you need to restart Postfix, run the following command:
    service postfix restart 
    • This assumes Ubuntu’s Service Command

Comments

Popular posts from this blog

Cambium cnPilot E400/E410/E500 Configuration Tutorial

Disabling Zimbra's AntiSpam, Amavis and AntiVirus filtering

Error "Unable to retrive Zimbra GPG key for package validation"