3

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?

Souman Mandal
  • 85
  • 1
  • 2
  • 5

2 Answers2

6

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.

Ladadadada
  • 25,847
  • 7
  • 57
  • 90
3

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.

Khaled
  • 35,688
  • 8
  • 69
  • 98