I have two email servers: mx1.example.com (IMAP, SMTP) and mx2.example.com (SMTP gateway).

  • mx1.example.com is handling email for example.com, example.net and example.org.
  • mx2.example.com is configured as a gateway for mx1.example.com
    (I want him to send out all mails that originate from mx1.example.com)

Now I want to send the emails

  • from example.com and example.net via mx1.example.com normally
  • from example.org via mx1.example.com (password auth) to the gateway mx2.example.com (IP).

How can I configure this?

UPDATE: Please hurry up guys, the bounty expires in 2 days.

To be more clear: I know how to relay via mx2.example.com (how to send everything via mx2.) I just have to put the IP of mx2 in relayhost in the main.cf in mx1. But I want to make this selectively, just for example.org.


3 Answers 3


you cannot use transport as it is used to transport emails to the MAILBOX, you need to use


it works like this in your main.cf:

relayhost = mx1.example.org, mx2.example.org 
relay_domains = example.com, example.org, example.net

smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/relaymap

/etc/postfix/relaymap looks like this :

@example.com    mx1.example.com
@example.net    mx1.example.com

@example.org    mx2.example.com
  • Need to put all config or with smtp_sender and sender_dependent it's ok? Jun 20, 2022 at 7:08
  • Only configuring relay_domains it's enough riight? Jun 20, 2022 at 7:12
  • I get the following error message postmap: fatal: relayhost parameter setting must not contain multiple values: example1.mail.protection.outlook.com, example2.mail.protection.outlook.com
    – supmethods
    Sep 15, 2022 at 2:27

by using the selective relay feature:

on mx1.example.com:

  • add a line : example.org smtp:mx2.example.com to /etc/postfix/transport

  • add a line : transport_maps = hash:/etc/postfix/transport to /etc/postfix/main.cf

  • run postmap /etc/postfix/transport
  • run postfix reload

on mx2.example.com :

  • add mx1.example.com to mynetworks in /etc/postfix/main.cf
  • make sure you have something like:

    smtpd_relay_restrictions = permit_mynetworks, reject_unauth_destination in /etc/postfix/main.cf it is missing

  • run postfix reload

Postfix to relay mails to other SMTP for particular domain






  • for some reason it is not working. I followed your proposal exactly It does not send the example.org via the mx2. It sends it out via mx1 like all other.
    – Max Muster
    Jun 13, 2020 at 15:24
  • please look in your /var/log folder , there should be files named ''mail.err mail.log` , in which you find essential information on what went wrong , please also check with postconf -n or by manually looking into the files that there is no parameter duplicate , also we might start a chat and you could send snippets of logs as suggested here : serverfault.com/questions/466461/…
    – Bash Stack
    Jun 14, 2020 at 10:26

Check, this settings must be:

mydestination =
relayhost =

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .