0

This article (https://www.sparkpost.com/resources/email-explained/return-path-explained/) explains "Return-Path" as follows:

When an email doesn’t make it to its intended destination, the return path indicates where non-delivery receipts—or bounce messages—are to be sent.

and

Many senders will incorporate identifiers into the return path address to ease handling of reply and bounce traffic, referred to as Variable Envelope Return Path (VERP).

I understand this as: "As the email sender, you specify the Return-Path header".

However, given the following answer (https://stackoverflow.com/a/28494070/9878135), it seems as if the receiving server always overwrites Return-Path:

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 address@example.com)

I'm currently trying to build an email server that uses VERP for emails. Let's say "john@example.com" wants to send an email to the outside. "From" should be "john@example.com" while "Return-Path" should be something completely different (like "bounce.hfuishnu@example.com"). When the outside email service can't deliver the email, it should send an email back to "bounce.hfuishnu@example.com". My server can now lookup this bounce email in the database and inform john@example.com about the delivery failure.

I'm using Postfix to send and receive mails (and Python to construct them). However, it seems as if Return-Path is never received by other email services (such as Google Mail or ProtonMail). Google Mail doesn't show the header at all while ProtonMail overwrites it with the "From" address.

So who does set the Return-Path header and why can't other email services receive mine?

AnFi
  • 6,103
  • 1
  • 14
  • 27
Myzel394
  • 101
  • 1
  • The confusion goes away as soon as you cleanly distinguish a) the "return path" the place where returns should go (these days a singular destination, the "envelope sender") and b) "Return-Path:" the header; a place to make this information available within the message (even for contexts where other envelope information is not). One a necessity of the transport, the other a useful convention at the final recipients discretion. – anx Feb 23 '23 at 22:54
  • I mean the `Return-Path` header, so the address where the receiving server should send the delivery report in case of a bounce – Myzel394 Feb 24 '23 at 11:17

1 Answers1

1

Return-Path: header contains a copy of "envelope sender" address. Return-Path: header is usually (re)generated by the SMTP/MTA making delivery directly to the recipient's mailbox (after the final SMTP hop).

"Envelope sender" is an address used in MAIL FROM: command in SMTP session.

So your sending client software should set "envelope sender" => It will be (usually) copied into Return-Path:.

SMTP.sendmail(from_addr, …)

AnFi
  • 6,103
  • 1
  • 14
  • 27
  • Why does the receiving server copy it? Isn't the point of `Return-Path` to define a **different** email address that can be used for bouncing by the server who sent the mail? – Myzel394 Feb 23 '23 at 10:00
  • `Return-Path:` informs the recipients about envelope sender address used in SMTP session because it is quite frequently different than `From:`. To make the information reliable the final hop SMTP/MTA server **usually** (re)creates it. Anyway: Now it is "a sacred tradition". – AnFi Feb 23 '23 at 12:46
  • Can I avoid the last MTA from recreating it? How do newsletters use VERP nowadays when it's a "sacred tradition"? Afaik DuckDuckGo's Email Tracking Protection also still uses it nowadays to detect when a forwarded email alias could not be delivered – Myzel394 Feb 23 '23 at 12:50
  • Use `from_address` when calling sendmail function. Provide address copied into `Return-Path:` header. Check it yourself to be 200% sure. VERP is based on "envelope sender" address. SMTP/MTA servers use "envelope sender" and ignore `Return-Path:` header when sending bounces. `Return-Path:` merely informs the final recipient about "envelope sender". – AnFi Feb 23 '23 at 13:35
  • Then what is `Return-Path` even used for when it gets overwritten anyway? The given article states that "When an email doesn’t make it to its intended destination, the return path indicates where non-delivery receipts—or bounce messages—are to be sent." – Myzel394 Feb 23 '23 at 15:02
  • `Return-Path:` makes envelope sender visible to the final recipient. "Envelope sender" defines destination for bounce emails. It creates confusion because `Return-Path:` is what the recipient sees/inspects. – AnFi Feb 23 '23 at 15:14
  • I think you misunderstood my question. I want the server to send to `Return-Path` for bounce mails. The other user should still see `From`. `Return-Path` should only be visible to the server, so normal users should normally never see it. Just like the article says: "Many senders will incorporate identifiers into the return path address to ease handling of reply and bounce traffic, referred to as Variable Envelope Return Path (VERP)." – Myzel394 Feb 23 '23 at 16:04