diff --git a/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php b/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php index 6650e6ad31cb8..0dfe9d1905547 100644 --- a/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php +++ b/src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php @@ -180,12 +180,15 @@ private function handleAuth(array $modes): void continue; } + $code = null; $authNames[] = $authenticator->getAuthKeyword(); try { $authenticator->authenticate($this); return; } catch (TransportExceptionInterface $e) { + $code = $e->getCode(); + try { $this->executeCommand("RSET\r\n", [250]); } catch (TransportExceptionInterface) { @@ -198,7 +201,7 @@ private function handleAuth(array $modes): void } if (!$authNames) { - throw new TransportException(sprintf('Failed to find an authenticator supported by the SMTP server, which currently supports: "%s".', implode('", "', $modes))); + throw new TransportException(sprintf('Failed to find an authenticator supported by the SMTP server, which currently supports: "%s".', implode('", "', $modes)), $code ?: 504); } $message = sprintf('Failed to authenticate on SMTP server with username "%s" using the following authenticators: "%s".', $this->username, implode('", "', $authNames)); @@ -206,6 +209,6 @@ private function handleAuth(array $modes): void $message .= sprintf(' Authenticator "%s" returned "%s".', $name, $error); } - throw new TransportException($message); + throw new TransportException($message, $code ?: 535); } }