Issues

ZF-8988: Zend Mail Transport SMTP set sender email address

Description

File: /Zend/Mail/Transport/Smtp.php Line: 207

In the smtp transport the from address is set with the following function:

// Set sender email address $this->_connection->mail($this->_mail->getFrom());

When sending a mail to an unknown user with a valid host. In most cased the headers will be read and the Return-Path header will be used to return the mail.

When sending a mail to a non-existing host. The smtp server will return the mail to the from address given in the smpt transport. The header has not been read.

In my opinion the sender email address must be set with the following function, so the bounce addresses goes to the return path.

// Set sender email address $this->_connection->mail($this->_mail->getReturnPath());

Which automatically fallback in the from address if return path is not set.

Comments

Funny that this was created yesterday. I recently had the same problem on a project I am working on. This should really be as simple as changing the function that is called. Hope that this fix can be included in the next mini release.

I saw the issue ZF-7008 but that one is using the php mail function:

"Sending mail with an additional command line parameter."

In my case i use the SMTP transport.

$transport = new Zend_Mail_Transport_Smtp('mail.example.com');

Because of that, i cannot use the function described in zend manual:

$transport = new Zend_Mail_Transport_Sendmail('-freturn_to_me@example.com');

I also agree that the MAIL FROM should be able to be overridable (either as a transport option or by interpretting the $mail->getReturnPath).

This is commonly used to forward bounces to another email address for processing, whilst allowing manually replied messages go back to the From address.

The Reply-To header isn't an option in these cases, as the bounce address might have additional information such as user id to be used to identify the non-existant email address for automatic unsubscription, and unnessary for the receiver to see the information (which clients seeing Reply-To, will also display the From).

Since sendmail supports setting this return path, please can the smtp class?

Please read http://www.ietf.org/rfc/rfc2821.txt regarding Return-Path

ZF-195 originally added this feature

ZF-8273 was incorrect, it was not a bug, and was what broke #ZF-195 and caused this issue.

The Return-Path is what is set in transit by the MAIL FROM, and any Return-Path header sent to Smtp is stripped. The From mail header gives the user the friendly reply address even when MAIL FROM is different.

To clarify, I believe this is a regression bug caused by ZF-8273 breaking Smtp Return-Path support, affecting ZF 1.9.6 onwards. (edited to correct version number)

Here is a patch to fix it.

I was asked on irc to include a unit test for this, so I've added a test to the SmtpTest, and included a mock SMTP protocol class needed for it, which fails before the patch and succeeds after.

Sorry, I have been inactive since last April.

Agreed, the behavior introduced by ZF-8273 is incorrect. The RFC 2821 states that both the MAIL FROM and the Return-Path header should be the same value:

The first step in the procedure is the MAIL command.

      MAIL FROM: [SP  ] 

... and ...

 The time stamp line and the return path line are formally defined as
   follows:

Return-path-line = "Return-Path:" FWS Reverse-path 

Andy, there are a couple of problems with your proposed patch. It doesn't run unless the TESTS_ZEND_MAIL_SMTP_ENABLED constant is set to true, which isn't necessary because this can be tested offline. Also the calls to addBcc(), addCc(), etc, aren't necessary to test this.

So, I'm attaching a simplified patch which includes a test that runs by default.

Applied to trunk in r23423, merged to 1.11 release branch in r23424

The same bug exists in Zend Framework 2.0 Beta 1. Could you please fix it there, too?