I want to rewrite all sender addresses @example.com to newsender@example.org (to one static outgoing address) but I also want to have the original address added as the reply-to. I can do either individually with the generic file and header_checks files respectively but as the generic file seems to be used first, I lose the original sender. Did I miss something from postfix rewrite documentation?

It would be OK if the envelope sender had something like original+mydomain.com@newsenderdom.com as long as From: header is newsender@newsenderdom.com. Any ideas?

If there is an easy solution in Qmail then that would also be an option!


After many hours searching and several posts (here and elsewhere) saying it isn't possible without a milter or with instructions that didn't work for me (like above), success!

At least with my testing on my setup, you cannot use smtp_generic_maps because that seems to be executed before other checks/rewrites. If you use sender_canonical_maps, however, then that seems to get executed after checks like header_checks. So, you can simply have the following in main.cf:

sender_canonical_maps = hash:/etc/postfix/sender_canonical_maps
header_checks = regexp:/etc/postfix/header_checks

Contents of files


@example.com    user@example.org


/^From:(.*)$/   PREPEND Reply-To:$1

And run postmap /etc/postfix/sender_canonical_maps

Restart postfix service postfix restart

And you're away laughing :-). This adds the expected Reply-to: whateverwasthere@example.com header and changes both the envelope & header from to user@example.org.

  • +1 Congratulations :) Sorry for misdirection solution :(. Anyway your conclusion about why smtp_generic_maps rewriting Reply-To wasn't right. This page stated that generic invoked right by smtp process, right before delivering email and after other rewrite rules. Unfortunately, the default behavior of generic process is also rewrite all header of email (including old From and new Reply-To header) – masegaloeh Nov 11 '14 at 6:59
  • Unfortunately, this does not seem to work on my system: in my sender_canonical_maps i have /.*/ sender@somehost.de, my header_checks matches your suggestion and still the reply-to address gets replaced by sender@somehost.de – Stephan Richter Feb 19 '18 at 17:14

Clearly there are two goals here:

  1. Append original sender to Reply-To header.
  2. Rewrite the sender into static value.

For first goal, using smtpd_sender_restriction + access maps should do the trick. Specify this paramater in main.cf

smtpd_sender_restriction = check_sender_access pcre:/etc/postfix/append_replyto.pcre

The content of /etc/postfix/append_replyto.pcre

/(.*)/  PREPEND Reply-To:$1

The map file will match all sender and append the it in Reply-To header.

The second goal is achieved with smtp_generic_maps. Whoops... looks like I'm missing a bit piece of generic behavior. It will rewrite all header (in From/Reply-To/other) and envelope.

The generic(5) mapping affects both message header addresses (i.e. addresses that appear inside messages) and message envelope addresses (for example, the addresses that are used in SMTP protocol commands).

For working solution, see the solution from the OP :)

  • 1
    Are you sure about this @masegaloeh? I am still getting newsender@example.org in the reply-to. I am running a standard ubuntu 12.04 (postfix 2.9.6) install. The only thing I changed was using regexp instead of pcre as pcre doesn't seem to be enabled by default. – AntonOfTheWoods Nov 11 '14 at 5:09

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.