Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

up vote 2 down vote accepted

In postfix, you can use transport_maps to specify different relay hosts for different domains. In file /etc/postfix/main.cf, 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
mydomain1.com :
mydomain2.com :

# Specify domains that need to be relayed through 192.168.1.1
anotherdomain1.com relay:192.168.1.1
anotherdomain2.com relay:192.168.1.1

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

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/main.cf:

header_checks = regexp:/etc/postfix/header_checks

In /etc/postfix/header_checks:

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

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

 
discard

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.