Postfix rewriting subject for specific addresses

emailpostfix

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?

Best Answer

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
endif

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

Related Question