diff --git a/lib/Cake/Network/Email/SmtpTransport.php b/lib/Cake/Network/Email/SmtpTransport.php index 72a669c10..971a5cefd 100644 --- a/lib/Cake/Network/Email/SmtpTransport.php +++ b/lib/Cake/Network/Email/SmtpTransport.php @@ -161,7 +161,10 @@ class SmtpTransport extends AbstractTransport { * @throws SocketException */ protected function _sendRcpt() { - $from = $this->_cakeEmail->from(); + $from = $this->_cakeEmail->returnPath(); + if (empty($from)) { + $from = $this->_cakeEmail->from(); + } $this->_smtpSend('MAIL FROM:<' . key($from) . '>'); $to = $this->_cakeEmail->to(); @@ -182,7 +185,7 @@ class SmtpTransport extends AbstractTransport { protected function _sendData() { $this->_smtpSend('DATA', '354'); - $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'returnPath', 'to', 'cc', 'subject')); + $headers = $this->_cakeEmail->getHeaders(array('from', 'sender', 'replyTo', 'readReceipt', 'to', 'cc', 'subject')); $headers = $this->_headersToString($headers); $lines = $this->_cakeEmail->message(); $messages = array(); diff --git a/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php b/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php index 7418afb79..ab4e1dbca 100644 --- a/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php +++ b/lib/Cake/Test/Case/Network/Email/SmtpTransportTest.php @@ -270,6 +270,28 @@ class SmtpTransportTest extends CakeTestCase { $this->SmtpTransport->sendRcpt(); } +/** + * testRcptWithReturnPath method + * + * @return void + */ + public function testRcptWithReturnPath() { + $email = new CakeEmail(); + $email->from('noreply@cakephp.org', 'CakePHP Test'); + $email->to('cake@cakephp.org', 'CakePHP'); + $email->returnPath('pleasereply@cakephp.org', 'CakePHP Return'); + + $this->socket->expects($this->at(0))->method('write')->with("MAIL FROM:\r\n"); + $this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false)); + $this->socket->expects($this->at(2))->method('read')->will($this->returnValue("250 OK\r\n")); + $this->socket->expects($this->at(3))->method('write')->with("RCPT TO:\r\n"); + $this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false)); + $this->socket->expects($this->at(5))->method('read')->will($this->returnValue("250 OK\r\n")); + + $this->SmtpTransport->setCakeEmail($email); + $this->SmtpTransport->sendRcpt(); + } + /** * testSendData method * @@ -290,7 +312,6 @@ class SmtpTransportTest extends CakeTestCase { $email->expects($this->any())->method('message')->will($this->returnValue(array('First Line', 'Second Line', '.Third Line', ''))); $data = "From: CakePHP Test \r\n"; - $data .= "Return-Path: CakePHP Return \r\n"; $data .= "To: CakePHP \r\n"; $data .= "Cc: Mark Story , Juan Basso \r\n"; $data .= "X-Mailer: CakePHP Email\r\n";