Archived Forum Post

Index of archived forum posts

Question:

How to set the Return-Path Header when Sending Email?

Jun 14 '12 at 09:18

Question from customer via email:
How to set the Return-Path header when sending email?


Answer

To answer this question, it's best to spend about two minutes to quickly understand the basics of the SMTP protocol. It's very easy:

The SMTP protocol works like this:

1) A client connects to an SMTP server.

2) The SMTP server says “hello”

3) The client authenticates (if necessary) by logging in.

4) Now it’s time to send an email. First, the client sends a “MAIL FROM” command with the email address that is the reverse-path. This is the email address that would receive a bounce or delivery status notification.

Note: The "MAIL FROM" address becomes the "Return-Path" header.
The receiving server adds the "Return-Path" to the email. (Just like it adds the "Received" header.) Therefore, a mail-sending app should never explicitly add the "Return-Path" header. The correct way of specifying the "Return-Path" is to pass the correct email address to "MAIL FROM" (see below).

5) The client then sends one or more “RCPT TO” commands, each with a recipient email address. It doesn’t matter if the recipient is a “To” , “CC”, or “BCC”, all recipient email addresses are passed to the SMTP server via “RCPT TO” commands.

6) Finally, the MIME source of the email is sent with a “DATA” command.
Note: The MIME source has header fields for “From”, “To”, and “CC”. These are the email addresses that will be seen by the receiver of the email. The actual recipients are the email addresses passed via the RCPT TO commands. It’s possible to create an email such that the “To” header field contains “santa.claus@northpole.com”, but you pass actual email addresses in the RCPT TO commands. The person receiving such an email (if not filtered as SPAM) would scratch his/her head and wonder why he/she received an email addressed to Santa Claus.

There are two ways to specify the "Return-Path" (i.e. the email address passed in the "MAIL FROM" command within the SMTP protocol.

1) If sending email by passing an email object to a method such as mailman.SendEmail, then set the emailObject.BounceAddress property. This is the address passed in the "MAIL FROM" command. If BounceAddress is unset, then the email object's From address is used.

2) If sending email by passing the exact MIME string, such as via mailman.SendMime, then the "fromAddr" argument is used.

A Note about BackScatter:

Now that you understand Return-Path, you can understand a problem called BackScatter. When a spammer sends millions of emails, the scoundrel will often pass a real email address (harvested from a web page) to the MAIL FROM command. A certain percentage of those emails are (of course) sent to invalid email addresses. A mail server managed by someone without a good understanding SMTP might configure the server to send DSN's (Delivery Status Notifications) for all undelivered emails. The end result is that the unlucky email address used by the spammer gets mail-bombed with DSN's. A good mail server administrator should either turn off DSN's, or only send DSN's for email known to NOT be SPAM.