4

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 protected]         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

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 protected]$/i
/^Subject: (.+)$/i REPLACE Subject: [Example tag] $1
endif

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

5
  • Is this also going to work if I want to change the sender of the mail for specific recipients? Commented 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. Commented 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: Commented Jun 9, 2018 at 2:37
  • 1
    I wish it would work this way, but unfortunately it cannot: serverfault.com/questions/498664/… Commented Jun 27, 2019 at 9:00
  • if ... endif just dealing the same string line, can't dealing multiple lines. So this doesn't work. Commented Apr 5, 2020 at 11:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.