Postfix Change subject based on recipient

6,838

Solution 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?

Solution 2

This can be done using transports and header checks.

In /etc/postfix/transport file add:

[email protected] custom_transport:

This will enable a particular transport for the desired recipient which will then be associated with the subject changes. Replace [email protected] 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

Share:
6,838
user3608560
Author by

user3608560

Updated on September 18, 2022

Comments

  • user3608560
    user3608560 over 1 year

    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.