3

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

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.

  • Is this also going to work if I want to change the sender of the mail for specific recipients? – wie5Ooma Jan 19 '18 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. – Luc-Olivier May 25 '18 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: – Murphy's Prophet Jun 9 '18 at 2:37

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.