Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In our application, we send different kind of mails. On a broad view we can generalize it in two category,

  1. Mails which monitor the health of the app.
  2. Mails which we send to end user.

Is there any way(Setting some header/configuring some parameter in postfix), such that for the same sender address, we can use different relay host?

share|improve this question
up vote 3 down vote accepted

In postfix, you can use transport_maps to specify different relay hosts for different domains. In file /etc/postfix/, you need to include a line:

transport_maps = hash:/etc/postfix/transport

The transport maps file has the following syntax:

# Syntax: .domain transport:relay_host
# Specifies specific domains for local delivery : :

# Specify domains that need to be relayed through relay: relay:

Don't forget to run postmap transport to generate the .db file and then reload/restart postfix process.

share|improve this answer
Thanks Khaled for the reply.....Worked like magic. :) – Souman Mandal May 8 '12 at 16:47
Thank you, but what if the different relay hosts require authentication? – Gabriele Jun 16 at 9:43

Transport maps (in Khaled's answer) can change the relay of mail based on the domain.

You can also use header_checks and body_checks to change transports (and perform other actions) based on matching headers and content found in the body of the email. These can be regex or hash based. My example below is regex based.

In /etc/postfix/

header_checks = regexp:/etc/postfix/header_checks

In /etc/postfix/header_checks:

/^Subject: Host [a-z0-9]* is down!/ FILTER relay:
/^Subject: [^ ]* has posted a new blog entry./ FILTER relay:
/^Message-ID: <[0-9a-z]*@dbserver.local>/ FILTER relay:
/^Message-ID: <[0-9a-z]*>/ FILTER relay:

The body_checks work the same way as the header_checks.

You can set arbitrary headers in your app if you want something unique to filter on.

share|improve this answer
Thanks Ladadadada, hope to use these approach for some advance filtering. – Souman Mandal May 8 '12 at 17:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.