Modifying Postfix message content

postfix

I am using postfix mail server and i need to replace mail content inside every incoming and outgoing message based on some predefined rules.

What is needed is to filter remote and local mail to replace every instance of user@domain.com in header or body with user@blah.com

header_checks and body_checks options seem cumbersome, maybe there is better/faster option that works on whole message instead going line by line

Best Answer

Postfix support header address rewriting at outgoing mail:

smtp_generic_maps = hash:/etc/postfix/generic_map

/etc/postfix/generic_map

user@example.com    user@example.org

# postmap /etc/postfix/generic_map

Using regular expression:

smtp_generic_maps = regexp:/etc/postfix/generic_map.regexp

/etc/postfix/generic_map

(.*?)@example.com    $1@example.org

Isn't supported change in body. You need create you own content filter.

http://www.postfix.org/postconf.5.html#smtp_generic_maps