2010/01/01 by Maarten Oelering.
About the Return-Path header
The most common error senders make is adding a Return-Path header to their mail. Even some well known mail software does this. Probably written by programmers who copy from others rather than reading RFCs (the internet standards that specify SMTP and MIME).
What does the standard say about Return-Path? The following fragment is from RFC 5321 which specifies the SMTP protocol:
When the delivery SMTP server makes the “final delivery” of a message, it inserts a return-path line at the beginning of the mail data. This use of return-path is required; mail systems MUST support it. The return-path line preserves the information in the from the MAIL command. Here, final delivery means the message has left the SMTP environment. Normally, this would mean it had been delivered to the destination user or an associated mail drop, but in some cases it may be further processed and transmitted by another mail system.
So when the email leaves the SMTP environment, for example by putting it in a mailbox, the Return-Path is added to preserve the value of the SMTP MAIL FROM command. Thus it is the mailbox provider (for example Google, Hotmail, Yahoo) that adds the Return-Path header.
When you look at the full header of a mail in your mailbox you will see the Return-Path header somewhere on top. Most often just above the Received header that shows the public IP where the mail was sent from. When you see a second Return-Path header somewhere below it is the wrong and extraneous header added by the sender.
You may be left with the question how to set the SMTP MAIL FROM, or envelope sender. This is the address where bounce mails are sent to. As an email service provider you want to set this to a generic address, different than the From: header, so you can process remote bounces.
The envelope sender is set where the mail enters the SMTP environment, often using an API such as JavaMail, System.Net.Mail.MailMessage, or PHPMailer. In Java it is not too difficult. You can set SMTP MAIL FROM via the mail.smtp.from property in JavaMail.
In .NET you have a problem. The MailMessage class allows you to set a Sender property, but then it also adds the Sender header. Otherwise your are forced to use a third-party mail library on Windows. Examples are mail.ddl, ASP.NET email or Chilkat.
In PHP’s mail function you can pass options to the underlying mail command. If sendmail is used the “-f” option will set the SMTP MAIL FROM. Note that PHPMailer adds a Return-Path header in the outgoing mail. So even they cannot be trusted to do it right.
Update: As of PHPMailer version 5.2.8 the Return-Path header is no longer set in created messages.
If you would like to know more about how we can help you, just send us a message via our contact page.