165

What's the difference between an email Sender, From and Return-Path value?

Example: I have a contact form where the user can input their email, would this be assigned to sender, from or return-path?

I had a quick search on the StackOverflow and couldn't find anything useful.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
The Pixel Developer
  • 13,282
  • 10
  • 43
  • 60

3 Answers3

207

So, over SMTP when a message is submitted, the SMTP envelope (sender, recipients, etc.) is different from the actual data of the message.

The Sender header is used to identify in the message who submitted it. This is usually the same as the From header, which is who the message is from. However, it can differ in some cases where a mail agent is sending messages on behalf of someone else.

The Return-Path header is used to indicate to the recipient (or receiving MTA) where non-delivery receipts are to be sent.

For example, take a server that allows users to send mail from a web page. So, sender@yourcompany.com types in a message and submits it. The server then sends the message to its recipient with From set to sender@yourcompany.com. The actual SMTP submission uses different credentials, something like mailagent@mywebmail.com. So, the sender header is set to mailagent@mywebmail.com, to indicate the From header doesn't indicate who actually submitted the message.

In this case, if the message cannot be sent, it's probably better for the agent to receive the non-delivery report, and so Return-Path would also be set to mailagent@mywebmail.com so that any delivery reports go to it instead of the sender.

If you are doing just that, a form submission to send e-mail, then this is probably a direct parallel with how you'd set the headers.

Shawn D.
  • 7,895
  • 8
  • 35
  • 47
  • 1
    As well, you don't have to set everything. i.e. if you leave out sender & return path, they go to the From address. If you leave out return path, NDRs go to the sender, I think. – Shawn D. Dec 06 '10 at 15:47
  • 1
    ... Which is an attractive nuisance for mail bombers. Don't do that! – tripleee Jan 10 '13 at 09:17
  • Do I understand this right? When talking about a web form for submitting an e-mail, the `Sender` is the _person_ who submitted the web form and the `From` is the _server_ that sent out the e-mail? Or is it the other way round? – Ethan Leroy Feb 06 '15 at 22:03
  • 9
    Imagine some VIP that has an assistant managing their mailbox. If the assistant is writing email on behalf of the VIP, the assistant is the `Sender`, but the message is `From` the VIP. This is what happens when you see email described as "From Assistant on behalf of VIP" – dewin Nov 20 '15 at 02:47
  • @ShawnD., What if there is no `Return-Path`. Does it default to the `Sender` then? – Pacerier Feb 14 '17 at 19:02
  • What happens in case of VERP? Where does the bounce go to? Thanks – Diego Ramos May 28 '22 at 23:42
  • @DiegoRamos Do you know the answer to this? I'm struggling with my `Return-Path` always being overwritten – Myzel394 Feb 23 '23 at 18:15
117

The official RFC which defines this specification could be found here:

https://www.rfc-editor.org/rfc/rfc4021#section-2.1.2 (look at paragraph 2.1.2. and the following)

2.1.2. Header Field: From

Description:  
    Mailbox of message author  
[...]  
Related information:
    Specifies the author(s) of the message; that is, the mailbox(es)
    of the person(s) or system(s) responsible for the writing of the
    message. Defined as standard by RFC 822.

2.1.3. Header Field: Sender

Description:  
    Mailbox of message sender  
[...]  
Related information:
    Specifies the mailbox of the agent responsible for the actual
    transmission of the message.  Defined as standard by RFC 822.

2.1.22. Header Field: Return-Path

Description:
    Message return path
[...]  
Related information:
    Return path for message response diagnostics. See also RFC 2821
    [17]. Defined as standard by RFC 822.
Community
  • 1
  • 1
stollr
  • 6,534
  • 4
  • 43
  • 59
  • 7
    Thanks for giving the official RFC link. It's really useful if someone ask, "Based on what?" – bayuah Nov 22 '15 at 23:29
  • 1
    [This other answer](http://stackoverflow.com/a/14555043/924299) (from 2011) claims that the method indicated here causes gmail to flag emails as spam. I wonder if that's still the case today. – showdev Dec 14 '16 at 23:04
  • 1
    Updated in RFC 5322 https://tools.ietf.org/html/rfc5322#section-3.6 . Can someone please tell the SMTP RFC people that it would help if the Sender field has to match the From address used in the SMTP handshake process if it is to be used. – BeowulfNode42 May 16 '19 at 05:09
31

A minor update to this: a sender should never set the Return-Path: header. There's no such thing as a Return-Path: header for a message in transit. That header is set by the MTA that makes final delivery, and is generally set to the value of the 5321.From unless the local system needs some kind of quirky routing.

It's a common misunderstanding because users rarely see an email without a Return-Path: header in their mailboxes. This is because they always see delivered messages, but an MTA should never see a Return-Path: header on a message in transit. See https://www.rfc-editor.org/rfc/rfc5321#section-4.4

Community
  • 1
  • 1
cmeid
  • 684
  • 6
  • 6
  • A sender using an email client would not set it, but a "sender" writing a script that sends emails may set it scriptually, thus I think its misleading to say a sender should never set it. – chiliNUT Apr 29 '15 at 15:33
  • 5
    Unfortunately, Chilinut is actually inaccurate. A Return-Path: header on a message in transit will be discarded, the MDA (mail deliver agent) that performs final delivery will set the Return-Path: header to match the value of the 5321.From (envelope-from) carried by the message. This is because the envelope is lost when the message is delivered, so the Return-Path: header records what the envelope-from was as the MDA received the message. – cmeid Apr 30 '15 at 16:06
  • I am looking at the headers of a message in my inbox right now, and it has a `From:` address, and a (*different*) `Return-Path:` address, so I don't know what you are referring to – chiliNUT Apr 30 '15 at 18:45
  • 2
    The `Return-Path:` header reflects the envelope-from, or RFC5321.From address. The `From:` header reflects the header-from, or RFC5322.From address. – cmeid Jun 22 '15 at 14:18
  • 7
    It's getting to be semantics, the important thing (as above) is that you cannot set a `Return-Path:` header when sending a message. If ones does, it will be discarded in transit and later set to the value of the RFC5321.From or envelope-from by the MDA that makes final delivery of the message. Basically the `Return-Path:` header records what the envelope-from had been, as the envelope is discarded on delivery. – cmeid Jun 23 '15 at 15:13
  • how is setting a return path different from setting an envelope from? – chiliNUT Jun 23 '15 at 16:17
  • 1
    The return path in the envelope of a message is the same as the envelope from. However, the `Return-Path:` header is part of the body of the message and is set by the MDA. – cmeid Nov 07 '17 at 17:41