Skip to content

Instantly share code, notes, and snippets.

@mgaulton
Forked from eegrok/postfix-modify-header
Created August 19, 2016 20:55
Show Gist options
  • Save mgaulton/5095e981b5ad60c197966b1226d4e21a to your computer and use it in GitHub Desktop.
Save mgaulton/5095e981b5ad60c197966b1226d4e21a to your computer and use it in GitHub Desktop.
Modify the to: header in postfix
# so recently I had an issue where I wanted to send email sent to a local user root (from logwatch, e.g.) to a different email address
# simple enough -- just add a ~root/.forward file, with the contents root-handler-testing@gmail.com
# all the email gets sent there...
# but the email shows up with a to: header of root@my-example-machine.com
# what I really want is the to: header to be root-handler-testing@gmail.com
# so I can filter emails, etc... below is how to do that.
#uncomment the following line in /etc/postfix/main.cf
#header_checks = regexp:/etc/postfix/header_checks
# then edit /etc/postfix/header_checks, and add a line like this:
# (replace root in the first line with the local username)
# and make sure the to: is lowercase -- even though it shows up in uppercase in my email client, uppercase doesn't match
# note that you can use WARN instead of REPLACE, and it will give you a log message if the regexp matches
# along with the full line that matched, so you can figure out what it should be
/^to:\s+root$/
REPLACE To: root-handler-testing@gmail.com
# then do:
sudo postmap /etc/postfix/header_checks
# and restart postfix
sudo postfix reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment