I would like to add a tag to all email messages sent to a particular address. I have tried to copy examples from the web, but can't seem to get it working.

Here's what I've done so far:

  1. Add to /etc/postfix/transport

    email@example.com         rewrite:
  2. Add to /etc/postfix/master.cf

    rewrite    unix  -       -       n       -       -       smtp
            -o header_checks=pcre:/etc/postfix/rewrite_headers
  3. Create /etc/postfix/rewrite_headers containing

    /^Subject: (.+)$/i    REPLACE Subject: [Example tag] $1

Where am I going wrong?

1 Answer 1


You should be able to do this without a custom transport, using built-in header checks.

Add to main.cf:

header_checks = pcre:/etc/postfix/rewrite_headers

Your rewrite_headers file will have the existing rule wrapped in a conditional:

if /^To: email@example.com$/i
/^Subject: (.+)$/i REPLACE Subject: [Example tag] $1

This should handle everything without the need for a transport config.

  • Is this also going to work if I want to change the sender of the mail for specific recipients?
    – wie5Ooma
    Jan 19, 2018 at 22:46
  • Thanks for the tips. Unfortunately for me, my postfix config doesn't work as per documentation. header_checks doc says the header is checked in one bunch, not line by line. But this doesn't work accordingly to my config. So your tip doesn't work on my config. May 25, 2018 at 14:54
  • There was a mistake in my config example. header_checks was set to a file path, but as it contains regex rules the path needs to be prefixed with pcre: Jun 9, 2018 at 2:37
  • 1
    I wish it would work this way, but unfortunately it cannot: serverfault.com/questions/498664/…
    – VPfB
    Jun 27, 2019 at 9:00
  • if ... endif just dealing the same string line, can't dealing multiple lines. So this doesn't work.
    – Sunry
    Apr 5, 2020 at 11:10

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.