1

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.

1

You probably need a content filter.

The Postfix documentation on builtin filters (which includes header_checks) specifies:

"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:

Postfix: content-filter vs. milter

You can use header_checks to send only the recipient-bound emails to the filter in question (to spare postfix the extra work):

How to rewrite email subject in postfix for outgoing mail if From contains specific address?

0

This can be done using transports and header checks.

In /etc/postfix/transport file add:

destination@address.com custom_transport:

This will enable a particular transport for the desired recipient which will then be associated with the subject changes. Replace destination@address.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.

References: http://www.postfix.org/header_checks.5.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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