We are using postfix as a mail relay. I am trying to change the subject of an email based on the recipient address. It looks like check_header is possibly the tool I need but I cant seem to have it filter on recipient but replace on subject.
You probably need a content filter.
"Header/body checks cannot depend on the recipient of a message."
The difference between a content-filter and a milter is that a milter happens before the queue:
You can use header_checks to send only the recipient-bound emails to the filter in question (to spare postfix the extra work):
This can be done using transports and header checks.
In /etc/postfix/transport file add:
This will enable a particular transport for the desired recipient which will then be associated with the subject changes. Replace email@example.com with the actual address. The name custom_transport is arbitrary but all references must be to the same name.
In /etc/postfix/main.cf add:
header_checks = regexp:/etc/postfix/header_checks transport_maps = hash:/etc/postfix/transport
These lines will enable header checks and transport maps respectively.
In /etc/postfix/master.cf add:
custom_transport ... smtp -o smtp_header_checks=regexp:/etc/postfix/rewrite_headers
Replacing ... with the rest of the smpt transport options already defined in that file.
Finally create the file /etc/postfix/rewrite_headers (the name is arbitrary but it must match the one in the line added to the master file) with the following content:
/^Subject:(.*)/ REPLACE Subject: Desired subject text
This will replace the subject with the desired one.
Reload or restart postfix.