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.