Return-Path
header is written by the receiving server, not by the sending server. And as per the RFC 5321, it is the same as the address supplied in MAIL FROM
command.
Even if you set the Return-Path
header yourself, the receiving server will overwrite that.
Now, here's the thing, the address in the MAIL FROM
command and the address in the From
header can be different. The receiving user does not see the MAIL FROM
address. They only see the From
header address.
So, if you want to ignore the bounces or want them to go to a specific address, you should use that address in the MAIL FROM
command.
But in the From
header, you can just use noreply@yourdomain.com
- the user will see this address.
To simplify a bit more, you send the email from handle_bounce@yourdomain.com
address. The receiving server will send the bounces to this address.
To show your user the noreply@yourdomain.com
address instead of handle_bounce...
address, set the From
header in the raw email MIME message to the noreply...
address.
I recently got a no-reply email from Bitbucket. Here's the raw message:
Return-Path: <bounce-1231860_HTML-1209402755-103116181-132689-225@bounce.mailer.atlassian.com>
From: "Atlassian Bitbucket" <noreply@mailer.bitbucket.org>
To: <me@hostname.com>
Subject: Continuous delivery, without the headache.
Date: Wed, 28 Feb 2018 12:40:53 -0600
MIME-Version: 1.0
Reply-To: "Atlassian Bitbucket" <reply-fe3915707665057b741c71-1231860_HTML-1209402755-132689-225@mailer.atlassian.com>
... message body ...
As you can see, the Return-Path
is an address dedicated to handle bounces. But the From
address is a noreply@...
mail. What that means is this email was actually sent by this bounce handling address, not by the noreply address.
You can also see the Reply-To
header, which is dedicated to handle replies, if a user replies to no-reply emails. Those replies are probably discarded right away.