Adding Reply-To header using Postfix if it does not exist in the mail headers

Kent asked:

I would like to add a Postfix re-write rule to insert a Reply-To: header if there is not one already defined.

This server is a web server with PHP and Perl scripts, we do not want the mail sent from this server to reply back to this server. Some of the scripts specify Reply-To: headers, others do not. I want set Reply-To: webmaster@domain.tld if the script has not already set one.

My answer:


It would be better (and easier) to simply rewrite the sender’s address; this will have the same effect, as well as doing some hiding of the internal topology (e.g. the sender won’t anymore be something like apache@webserver6.example.com).

You can easily rewrite the sender of all outgoing mail with smtp_generic_maps. For instance, to change the sender of all outgoing mail to webmaster@example.com:

In /etc/postfix/main.cf:

smtp_generic_maps = hash:/etc/postfix/generic

In /etc/postfix/generic:

*                       webmaster@example.com

Then run postmap /etc/postfix/generic and service postfix reload.

See generic(5) for more options on rewriting sender addresses and the ADDRESS REWRITING README for everything you ever wanted to know about address transformations.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.