8000 [Mailer] Allow manually start()/stop() of SmtpTransport · symfony/symfony@a998806 · GitHub
[go: up one dir, main page]

Skip to content

Commit a998806

Browse files
committed
[Mailer] Allow manually start()/stop() of SmtpTransport
1 parent fac3060 commit a998806

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/Symfony/Component/Mailer/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Allow manually start()/stop() of `SmtpTransport`
8+
49
6.0
510
---
611

src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ public function testWriteEncodedRecipientAndSenderAddresses()
133133
$this->assertContains("RCPT TO:<recipient@xn--exmple-cua.org>\r\n", $stream->getCommands());
134134
$this->assertContains("RCPT TO:<recipient2@example.org>\r\n", $stream->getCommands());
135135
}
136+
137+
public function testStartStop() {
138+
$stream = new DummyStream();
139+
140+
$transport = new SmtpTransport($stream);
141+
142+
$transport->start();
143+
$this->assertFalse($stream->isClosed());
144+
145+
$transport->stop();
146+
$this->assertTrue($stream->isClosed());
147+
}
136148
}
137149

138150
class DummyStream extends AbstractStream

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ private function doRcptToCommand(string $address): void
240240
$this->executeCommand(sprintf("RCPT TO:<%s>\r\n", $address), [250, 251, 252]);
241241
}
242242

243-
private function start(): void
243+
/**
244+
* Manually connect to the SMTP server, will happen automatically when sending mails.
245+
*
246+
* @throws TransportException If the connection fails to be established
247+
*/
248+
public function start(): void
244249
{
245250
if ($this->started) {
246251
return;
@@ -257,7 +262,10 @@ private function start(): void
257262
$this->getLogger()->debug(sprintf('Email transport "%s" started', __CLASS__));
258263
}
259264

260-
private function stop(): void
265+
/**
266+
* Manually disconnect from the SMTP server.
267+
*/
268+
public function stop(): void
261269
{
262270
if (!$this->started) {
263271
return;

0 commit comments

Comments
 (0)
0