How to configure postfix to force From: field but leave Reply-To: alone

emailpostfix

I need to configure postfix on a localhost as a relay to an smtp server.
This external smtp server requires From: header to be consistent with the authenticated user name.
I want to fixup the From: header for all the messages originating on this local machine to say authenticated@example.com

I tried the following:

  1. sender_canonical_maps
    The problem is: it seems to be overwriting the Reply-To: header as well, I don't need this, on the contrary, I want to use it extensively.

How I checked this:

  • Put sender_canonical_maps = regexp:/etc/postfix/sender_canonical in main.cf
  • REPLYTO="some.addr@gmail.com" mail my_addr@gmail.com
  • Actual results: received message has overwritten Reply-To to authenticated@example.com

Vs:

  • Remove sender_canonical_maps from main.cf
  • REPLYTO="some.addr@gmail.com" mail -r authenticated@example.com my_addr@gmail.com
  • Actual results: received message has correct Reply-To

The problem is this doesn't work without -r authenticated@example.com.

  1. header_checks: apparently doesn't work for From: fields (http://www.postfix.org/header_checks.5.html see Bugs: section)

How can I simply force the From: header on all outgoing mail, but leave Reply-To: alone for local users to specify?

Best Answer

Forcing the from address when postfix relays over smtp

/etc/postfix/main.cf:

smtp_header_checks = regexp:/etc/postfix/header_check

/etc/postfix/header_check:

/From:.*/ REPLACE From: newsender@address.com

Tested with:

mail -s test -a 'Reply-To: a@domain.tld' me@me.com <<< test

Header on client side:

From: newsender@address.com
Reply-To: a@domain.tld
To: <me@me.com>

In syslog you then see

Nov  1 17:20:50 huuu postfix/smtp[4716]: 1B65481FAB18: replace: header From: root@huuu (root): From: newsender@address.com