2

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?

  • What is the mail client you are using, you can achieve this easily with mail clients. – Anirudh Malhotra Oct 30 '16 at 1: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 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
3
+50

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
  • Very weird, it didn't work for me as stated in the question. I'll give it a second try – unkulunkulu Nov 2 '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 3 '16 at 5: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.

  • 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 7 '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 7 '16 at 14:13

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.