8000 [Mailer] Fix error message in case of an STMP error · symfony/symfony@447a9e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 447a9e3

Browse files
committed
[Mailer] Fix error message in case of an STMP error
1 parent 42938ef commit 447a9e3

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ protected function doHeloCommand(): void
120120
$response = $this->executeCommand(sprintf("EHLO %s\r\n", $this->getLocalDomain()), [250]);
121121
$capabilities = $this->getCapabilities($response);
122122
} catch (TransportExceptionInterface $e) {
123-
parent::doHeloCommand();
123+
try {
124+
parent::doHeloCommand();
125+
} catch (TransportExceptionInterface $ex) {
126+
if (!$ex->getCode()) {
127+
throw $e;
128+
}
129+
}
124130

125131
return;
126132
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public function __toString(): string
176176
public function executeCommand(string $command, array $codes): string
177177
{
178178
$this->stream->write($command);
179+
179180
$response = $this->getFullResponse();
180181
$this->assertResponseCode($response, $codes);
181182

@@ -295,15 +296,11 @@ private function assertResponseCode(string $response, array $codes): void
295296
throw new LogicException('You must set the expected response code.');
296297
}
297298

298-
if (!$response) {
299-
throw new TransportException(sprintf('Expected response code "%s" but got an empty response.', implode('/', $codes)));
300-
}
301-
302299
[$code] = sscanf($response, '%3d');
303300
$valid = \in_array($code, $codes);
304-
305301
if (!$valid) {
306-
throw new TransportException(sprintf('Expected response code "%s" but got code "%s", with message "%s".', implode('/', $codes), $code, trim($response)), $code);
302+
$extra = $response ? sprintf(', with message "%s"', trim($response)) : '';
303+
throw new TransportException(sprintf('Expected response code "%s" but got code "%s"%s.', implode('/', $codes), $code, $extra), $code);
307304
}
308305
}
309306

0 commit comments

Comments
 (0)
0