Skip to content

Commit 3b36239

Browse files
committed
[Mailer] Use better error code when auth fails
1 parent 6eef692 commit 3b36239

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,15 @@ private function handleAuth(array $modes): void
180180
continue;
181181
}
182182

183+
$code = null;
183184
$authNames[] = $authenticator->getAuthKeyword();
184185
try {
185186
$authenticator->authenticate($this);
186187

187188
return;
188189
} catch (TransportExceptionInterface $e) {
190+
$code = $e->getCode();
191+
189192
try {
190193
$this->executeCommand("RSET\r\n", [250]);
191194
} catch (TransportExceptionInterface) {
@@ -198,14 +201,14 @@ private function handleAuth(array $modes): void
198201
}
199202

200203
if (!$authNames) {
201-
throw new TransportException(sprintf('Failed to find an authenticator supported by the SMTP server, which currently supports: "%s".', implode('", "', $modes)));
204+
throw new TransportException(sprintf('Failed to find an authenticator supported by the SMTP server, which currently supports: "%s".', implode('", "', $modes)), $code ?: 504);
202205
}
203206

204207
$message = sprintf('Failed to authenticate on SMTP server with username "%s" using the following authenticators: "%s".', $this->username, implode('", "', $authNames));
205208
foreach ($errors as $name => $error) {
206209
$message .= sprintf(' Authenticator "%s" returned "%s".', $name, $error);
207210
}
208211

209-
throw new TransportException($message);
212+
throw new TransportException($message, $code ?: 535);
210213
}
211214
}

0 commit comments

Comments
 (0)