Reputation: 736
I'm sending mails from PHP using postfix at ubuntu:
mail($to, $subject, $body, "Return-Path: <[email protected]>");
Trying to set Return-Path
header but it seems that postfix rewrites it to user@serverdomain
Found in postfix documentation message_drop_headers
variable that by default has value bcc, content-length, resent-bcc, return-path
Tried to change it's value in postfix/main.cf
but it gives warning on start:
/usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: message_drop_headers=bcc content-length resent-bcc
What could be the reason? How can I configure postfix not to rewrite Return-Path header?
Upvotes: 4
Views: 9579
Reputation: 280
The solution is to declare a smtp_generic_maps table in Postfix main.cf and list local user and corresponding email in it.
For example : www-data [email protected]
Look at https://www.postfix.org/generic.5.html for more infos.
Of course use only a real domain you manage and with at least a SPF record allowing sending mails from this server.
Upvotes: 0
Reputation: 189377
Setting the Return-Path:
header on outbound email is pointless because it will be replaced by the recipient's MTA. If you want to control what gets written there, set the envelope sender (traditionally, sendmail -f [email protected]
)
In some more detail, when you send a message, there are two layers: An envelope, which specifies the actual recipients, and the message itself, which often contains headers with the same information ... but sometimes it doesn't, and sometimes those headers lie, blatantly.
When that message is delivered to a recipient, the receiving MTA (Sendmail or Postfix or Exchange or what have you) will copy the envelope sender information into the Return-Path:
header, adding one if it's missing, and usually simply overwriting it if it already existed.
So it doesn't really matter how you configure Return-Path:
on your outgoing server; in order to properly control this, you would need to control the receiving behavior on every server which delivers the message to a recipient.
As a trivial example, subscribe to a public mailing list, observe how the headers often say something like:
From: Popular mailing list <[email protected]>
To: Popular mailing list <[email protected]>
And yet it arrived in your inbox. How did that happen? Why, by way of the envelope recipient information. The list software basically adds a Bcc:
to every subscriber, but also convinces the server to ignore the actual To:
address in the headers. This is surprising until you realize that the headers actually don't matter, and only the envelope addresses actually control where the message is eventually delivered.
Briefly, the envelope is specified by the SMTP MAIL FROM:
and RCPT TO:
verbs which are defined in RFC5321 (originally 822) and the actual message (including all the headers) are communicatd in the SMTP DATA
section which is really just pure data as far as SMTP is concerned at this point. Their specification is RFC5322 (née 822) and once a message is actually delivered, the receiving server will actually add some headers of its own, but the From:
and To:
headers are still just basically ignored.
Upvotes: 4