3

I want to rewrite all sender addresses @example.com to [email protected] (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 [email protected] as long as From: header is [email protected]. Any ideas?

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

2 Answers 2

4

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

/etc/postfix/sender_canonical_maps:

@example.com    [email protected]

/etc/postfix/header_checks:

/^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: [email protected] header and changes both the envelope & header from to [email protected].

2
  • +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, 2014 at 6:59
  • Unfortunately, this does not seem to work on my system: in my sender_canonical_maps i have /.*/ [email protected], my header_checks matches your suggestion and still the reply-to address gets replaced by [email protected] Feb 19, 2018 at 17:14
0

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
  • 1
    Are you sure about this @masegaloeh? I am still getting [email protected] 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. Nov 11, 2014 at 5:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .