8000 [Mailer] Allow manually stop() of SmtpTransport by dvaeversted · Pull Request #45307 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mailer] Allow manually stop() of SmtpTransport #45307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Mailer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.1
---

* Allow manually stop() of `SmtpTransport`

6.0
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ public function testWriteEncodedRecipientAndSenderAddresses()
$this->assertContains("RCPT TO:<recipient@xn--exmple-cua.org>\r\n", $stream->getCommands());
$this->assertContains("RCPT TO:<recipient2@example.org>\r\n", $stream->getCommands());
}

public function testStop()
{
$stream = new DummyStream();
$envelope = new Envelope(new Address('sender@example.org'), [new Address('recipient@example.org')]);

$transport = new SmtpTransport($stream);
$transport->send(new RawMessage('Message 1'), $envelope);
$this->assertFalse($stream->isClosed());

$transport->stop();
$this->assertTrue($stream->isClosed());
}
}

class DummyStream extends AbstractStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ private function start(): void
$this->getLogger()->debug(sprintf('Email transport "%s" started', __CLASS__));
}

private function stop(): void
/**
* Manually disconnect from the SMTP server.
*
* In most cases this is not necessary since the disconnect happens automatically on termination.
* In cases of long-running scripts, this might however make sense to avoid keeping an open
* connection to the SMTP server in between sending emails.
*/
public function stop(): void
{
if (!$this->started) {
return;
Expand Down
0