Skip to content

Commit 94a54ca

Browse files
committed
[Mailer] Improve an exception when trying to send a RawMessage without an Envelope
1 parent 610a4e9 commit 94a54ca

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Symfony/Component/Mailer/Tests/Transport/AbstractTransportTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Mailer\Tests\Transport;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Mailer\Exception\LogicException;
1516
use Symfony\Component\Mailer\SmtpEnvelope;
1617
use Symfony\Component\Mailer\Transport\NullTransport;
1718
use Symfony\Component\Mime\Address;
@@ -46,4 +47,12 @@ public function testThrottling()
4647
$transport->send($message, $envelope);
4748
$this->assertEqualsWithDelta(0, time() - $start, 1);
4849
}
50+
51+
public function testSendingRawMessages()
52+
{
53+
$this->expectException(LogicException::class);
54+
55+
$transport = new NullTransport();
56+
$transport->send(new RawMessage('Some raw email message'));
57+
}
4958
}

src/Symfony/Component/Mailer/Transport/AbstractTransport.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\EventDispatcher\EventDispatcher;
1717
use Symfony\Component\Mailer\DelayedSmtpEnvelope;
1818
use Symfony\Component\Mailer\Event\MessageEvent;
19+
use Symfony\Component\Mailer\Exception\LogicException;
1920
use Symfony\Component\Mailer\Exception\TransportException;
2021
use Symfony\Component\Mailer\SentMessage;
2122
use Symfony\Component\Mailer\SmtpEnvelope;
@@ -59,6 +60,8 @@ public function send(RawMessage $message, SmtpEnvelope $envelope = null): ?SentM
5960
$message = clone $message;
6061
if (null !== $envelope) {
6162
$envelope = clone $envelope;
63+
} elseif (RawMessage::class === \get_class($message)) {
64+
throw new LogicException('Cannot send a RawMessage instance without an explicit Envelope.');
6265
} else {
6366
try {
6467
$envelope = new DelayedSmtpEnvelope($message);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy