Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4ad5d46

Browse filesBrowse files
committed
feature symfony#45307 [Mailer] Allow manually stop() of SmtpTransport (dvaeversted)
This PR was merged into the 6.1 branch. Discussion ---------- [Mailer] Allow manually stop() of SmtpTransport | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix symfony#43237 | License | MIT | Doc PR | Mark the `stop()` method on SmtpTransport as public, to allow greater control in long running jobs and similar. Commits ------- ac6c519 [Mailer] Allow manually start()/stop() of SmtpTransport
2 parents fac3060 + ac6c519 commit 4ad5d46
Copy full SHA for 4ad5d46

File tree

3 files changed

+26
-1
lines changed
Filter options

3 files changed

+26
-1
lines changed

‎src/Symfony/Component/Mailer/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/CHANGELOG.md
+5Lines 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 stop() of `SmtpTransport`
8+
49
6.0
510
---
611

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Tests/Transport/Smtp/SmtpTransportTest.php
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ 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 testStop()
138+
{
139+
$stream = new DummyStream();
140+
$envelope = new Envelope(new Address('sender@example.org'), [new Address('recipient@example.org')]);
141+
142+
$transport = new SmtpTransport($stream);
143+
$transport->send(new RawMessage('Message 1'), $envelope);
144+
$this->assertFalse($stream->isClosed());
145+
146+
$transport->stop();
147+
$this->assertTrue($stream->isClosed());
148+
}
136149
}
137150

138151
class DummyStream extends AbstractStream

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mailer/Transport/Smtp/SmtpTransport.php
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,14 @@ private function start(): void
257257
$this->getLogger()->debug(sprintf('Email transport "%s" started', __CLASS__));
258258
}
259259

260-
private function stop(): void
260+
/**
261+
* Manually disconnect from the SMTP server.
262+
*
263+
* In most cases this is not necessary since the disconnect happens automatically on termination.
264+
* In cases of long-running scripts, this might however make sense to avoid keeping an open
265+
* connection to the SMTP server in between sending emails.
266+
*/
267+
public function stop(): void
261268
{
262269
if (!$this->started) {
263270
return;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.