ZF-10249: Missing inclusion of SMTP status code in Zend_Mail_Protocol_Exception

Description

I asked this month before but never received a satisfying answers:

If I Use a Zend_Mail_Transport_Smtp for mail transport. How could I receive the Status code returned by the server on any errors.

Example: 451 greylisted - try again later

The Zend_Mail_Protocol_Exception only contains the "greylisted - try again later" which may vary between servers. The getCode() Method only returns 0.

To me this is a bug of the Zend_Mail_Transport_Smtp and I can't believe that noone else had this problem before.

Comments

Maybe it could be possible to modify Zend_Mail_Protocol_Abstract::_expect() to submit servers response code via Exception code (which should solve my problem):

{color:red} $errCode = 0;{color} do { $this->_response[] = $result = $this->_receive($timeout); list($cmd, $more, $msg) = preg_split('/([\s-]+)/', $result, 2, PREG_SPLIT_DELIM_CAPTURE);

        if ($errMsg !== '') {
            $errMsg .= ' ' . $msg;
        } elseif ($cmd === null || !in_array($cmd, $code)) {
            {color:red} $errCode = $cmd;{color}
            $errMsg =  $msg;
        }

} while (strpos($more, '-') === 0);

if ($errMsg !== '') { /** * @see Zend_Mail_Protocol_Exception */ require_once 'Zend/Mail/Protocol/Exception.php'; throw new Zend_Mail_Protocol_Exception($errMsg{color:red}, $errCode{color}); }

Thanks for the bug report. Addressed this in the patch attached to ZF-10741 as it was necessary to have access to the SMTP status codes for the unit tests on ZF-10741.

Closing this ticket as duplicate for now and linking to ZF-10741 for resolution.