Skip to content

Commit d36ac00

Browse files
committed
bug #32895 [Mailer] Fix error not being thrown properly (fabpot)
This PR was merged into the 4.3 branch. Discussion ---------- [Mailer] Fix error not being thrown properly | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | n/a | License | MIT | Doc PR | n/a When the SMTP server returns a fatal error, the error is not thrown properly as catched and another error (empty) is thrown. That makes debugging very difficult and what we would expect anyway. Commits ------- 15dbe4b948 [Mailer] fixed error that is masked by another error
2 parents 5160b44 + 52cb0ea commit d36ac00

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

Smtp/SmtpTransport.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
114114
try {
115115
$message = parent::send($message, $envelope);
116116
} catch (TransportExceptionInterface $e) {
117-
$this->executeCommand("RSET\r\n", [250]);
117+
try {
118+
$this->executeCommand("RSET\r\n", [250]);
119+
} catch (TransportExceptionInterface $_) {
120+
// ignore this exception as it probably means that the server error was final
121+
}
118122

119123
throw $e;
120124
}

SmtpTransport.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
114114
try {
115115
$message = parent::send($message, $envelope);
116116
} catch (TransportExceptionInterface $e) {
117-
$this->executeCommand("RSET\r\n", [250]);
117+
try {
118+
$this->executeCommand("RSET\r\n", [250]);
119+
} catch (TransportExceptionInterface $_) {
120+
// ignore this exception as it probably means that the server error was final
121+
}
118122

119123
throw $e;
120124
}

Transport/Smtp/SmtpTransport.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
114114
try {
115115
$message = parent::send($message, $envelope);
116116
} catch (TransportExceptionInterface $e) {
117-
$this->executeCommand("RSET\r\n", [250]);
117+
try {
118+
$this->executeCommand("RSET\r\n", [250]);
119+
} catch (TransportExceptionInterface $_) {
120+
// ignore this exception as it probably means that the server error was final
121+
}
118122

119123
throw $e;
120124
}

0 commit comments

Comments
 (0)