3

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?

unkulunkulu
  • 81
  • 1
  • 1
  • 7
  • What is the mail client you are using, you can achieve this easily with mail clients. – Anirudh Malhotra Oct 30 '16 at 01:30
  • This is for automatically sending mail from different scripts running on the machine, I want to configure this once and for all and not bother checking every script/mail client for correct configuration. – unkulunkulu Oct 31 '16 at 10:58
  • Yes absolutely, There is a mail client **mutt** which does this precisely. You can create automated scripts and send mail. Plus there is a muttrc file in which you can set variables(To:, From:, Reply-To:, et al). Hope this helps! – Anirudh Malhotra Oct 31 '16 at 11:01
  • I know how I could solve this problem if I started from scratch, this is not the point of this question. I already have some processes which send mail via local postfix, I just want to migrate to another smtp relay which has additional restrictions. What I need here is an answer to precisely the question: how to do this apparently simple thing in postfix. – unkulunkulu Oct 31 '16 at 13:44
  • Well as I asked in my first comment "what is your e-mail client", which you chose not to answer. Now **apparently** the thing you want is the job of an MUA(mail client) and not an MTA(postfix). Refer the [link](https://wiki.list.org/DOC/What%20is%20an%20MTA%3F%20What%20is%20an%20MUA%3F%20What%20is%20an%20MDA%20or%20LDA%3F) to know the difference. The rewrite option you tried is for cleaning up not for what you are trying to achieve. I am here only to help you if you let me. – Anirudh Malhotra Oct 31 '16 at 15:35
  • What is your upstream mta? Sounds like you are trying to send stuff via gmail as a smarthost and have replies go back to the origin. – Jacob Evans Oct 31 '16 at 23:15
  • Does it really matter? Let's say this is kind of "ok I spent ours on this and now I want to know how it's supposed to be done". I really can do this whole stuff without those postfix hacks. It's just unbelievable that this kind of behaviour is so hard to achive. – unkulunkulu Nov 01 '16 at 09:37

2 Answers2

5

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
Yarik Dot
  • 1,543
  • 12
  • 26
  • 1
    Very weird, it didn't work for me as stated in the question. I'll give it a second try – unkulunkulu Nov 02 '16 at 14:57
  • 1
    Tested on Debian Jessie. Postfix version 2.11.3-1. I have added log message I see in syslog to the answer. – Yarik Dot Nov 03 '16 at 05:15
  • For others who found this, note that the default header check file (at least on CentOS 7 Postfix 2.10.1) is `/etc/postfix/header_checks`, i.e., plural. – jeremysprofile Jul 20 '18 at 17:14
0

Check out the "Generic mapping for outgoing SMTP mail" at: http://www.postfix.org/ADDRESS_REWRITING_README.html

Grt. R.

Rob Tan
  • 1
  • 1
  • 1
    Hi. Thanks for this link. But I have already read it (just wasn't able to solve my problem). Here on stackexchange actual answers to the question are very valuable (i.e. add such and such lines to your configs etc), not just RTFM links :) – unkulunkulu Nov 07 '16 at 14:05
  • To me it seems the answer to your problem. if you send to whatever email adres on the internet with, the smtp_generic_maps can map your local address to your authenticate@example.com address. – Rob Tan Nov 07 '16 at 14:13