Add additional information to the smtp error message. (#1420)

This commit is contained in:
RainLoop 2017-11-11 21:38:41 +03:00
parent e0ba6aba9f
commit 20b373480d

View file

@ -413,7 +413,10 @@ class SmtpClient extends \MailSo\Net\NetClient
$sCmd .= ' NOTIFY=SUCCESS,FAILURE'; $sCmd .= ' NOTIFY=SUCCESS,FAILURE';
} }
$this->sendRequestWithCheck('RCPT', array(250, 251), $sCmd); $this->sendRequestWithCheck(
'RCPT', array(250, 251), $sCmd, false,
'Failed to add recipient "'.$sTo.'"'
);
$this->bRcpt = true; $this->bRcpt = true;
@ -657,6 +660,7 @@ class SmtpClient extends \MailSo\Net\NetClient
* @param int|array $mExpectCode * @param int|array $mExpectCode
* @param string $sAddToCommand = '' * @param string $sAddToCommand = ''
* @param bool $bSecureLog = false * @param bool $bSecureLog = false
* @param string $sErrorPrefix = ''
* *
* @return void * @return void
* *
@ -664,10 +668,10 @@ class SmtpClient extends \MailSo\Net\NetClient
* @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Smtp\Exceptions\Exception * @throws \MailSo\Smtp\Exceptions\Exception
*/ */
private function sendRequestWithCheck($sCommand, $mExpectCode, $sAddToCommand = '', $bSecureLog = false) private function sendRequestWithCheck($sCommand, $mExpectCode, $sAddToCommand = '', $bSecureLog = false, $sErrorPrefix = '')
{ {
$this->sendRequest($sCommand, $sAddToCommand, $bSecureLog); $this->sendRequest($sCommand, $sAddToCommand, $bSecureLog);
$this->validateResponse($mExpectCode); $this->validateResponse($mExpectCode, $sErrorPrefix);
} }
/** /**
@ -758,12 +762,13 @@ class SmtpClient extends \MailSo\Net\NetClient
/** /**
* @param int|array $mExpectCode * @param int|array $mExpectCode
* @param string $sErrorPrefix = ''
* *
* @return void * @return void
* *
* @throws \MailSo\Smtp\Exceptions\ResponseException * @throws \MailSo\Smtp\Exceptions\ResponseException
*/ */
private function validateResponse($mExpectCode) private function validateResponse($mExpectCode, $sErrorPrefix = '')
{ {
if (!\is_array($mExpectCode)) if (!\is_array($mExpectCode))
{ {
@ -786,7 +791,8 @@ class SmtpClient extends \MailSo\Net\NetClient
if ('-' !== \substr($aParts[1], 0, 1) && !\in_array((int) $aParts[0], $mExpectCode)) if ('-' !== \substr($aParts[1], 0, 1) && !\in_array((int) $aParts[0], $mExpectCode))
{ {
$this->writeLogException( $this->writeLogException(
new Exceptions\NegativeResponseException($this->aResults, \trim( new Exceptions\NegativeResponseException($this->aResults,
('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim(
(0 < \count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : ''). (0 < \count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : '').
$this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true); $this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true);
} }
@ -794,7 +800,8 @@ class SmtpClient extends \MailSo\Net\NetClient
else else
{ {
$this->writeLogException( $this->writeLogException(
new Exceptions\ResponseException($this->aResults, \trim( new Exceptions\ResponseException($this->aResults,
('' === $sErrorPrefix ? '' : $sErrorPrefix.': ').\trim(
(0 < \count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : ''). (0 < \count($this->aResults) ? \implode("\r\n", $this->aResults)."\r\n" : '').
$this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true); $this->sResponseBuffer)), \MailSo\Log\Enumerations\Type::ERROR, true);
} }