Skip to content

Commit 288952c

Browse files
Merge branch '4.4'
* 4.4: cs fix [Mailer] Check email validity before opening an SMTP connection
2 parents 6ca1d8c + 2a43f5b commit 288952c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

SentMessage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class SentMessage
2929
*/
3030
public function __construct(RawMessage $message, SmtpEnvelope $envelope)
3131
{
32+
$message->ensureValidity();
33+
3234
$this->raw = $message instanceof Message ? new RawMessage($message->toIterable()) : $message;
3335
$this->original = $message;
3436
$this->envelope = $envelope;

Transport/Smtp/SmtpTransport.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,18 +104,15 @@ public function getLocalDomain(): string
104104

105105
public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentMessage
106106
{
107-
$this->ping();
108-
if (!$this->started) {
109-
$this->start();
110-
}
111-
112107
try {
113108
$message = parent::send($message, $envelope);
114109
} catch (TransportExceptionInterface $e) {
115-
try {
116-
$this->executeCommand("RSET\r\n", [250]);
117-
} catch (TransportExceptionInterface $_) {
118-
// ignore this exception as it probably means that the server error was final
110+
if ($this->started) {
111+
try {
112+
$this->executeCommand("RSET\r\n", [250]);
113+
} catch (TransportExceptionInterface $_) {
114+
// ignore this exception as it probably means that the server error was final
115+
}
119116
}
120117

121118
throw $e;
@@ -163,6 +160,11 @@ public function executeCommand(string $command, array $codes): string
163160

164161
protected function doSend(SentMessage $message): void
165162
{
163+
$this->ping();
164+
if (!$this->started) {
165+
$this->start();
166+
}
167+
166168
try {
167169
$envelope = $message->getEnvelope();
168170
$this->doMailFromCommand($envelope->getSender()->getAddress());

Transport/Smtp/Stream/SocketStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class SocketStream extends AbstractStream
2626
private $url;
2727
private $host = 'localhost';
2828
private $port = 465;
29-
private $timeout = 15;
29+
private $timeout = 5;
3030
private $tls = true;
3131
private $sourceIp;
3232
private $streamContextOptions = [];

0 commit comments

Comments
 (0)