Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Templated email messages fails when sending async #39190

Closed
@ronnylt

Description

@ronnylt

Symfony version(s) affected: 5.x

Description
When sending a TemplatedEmail asynchronously, an exception is thrown : Symfony\Component\Mime\Exception\LogicException: A message must have a text or an HTML part or attachments..

The rendering of the templated is not done, as it's deferred to the actual email sending, but when the messenger's message is created it fails:

1) Symfony\Bundle\FrameworkBundle\Tests\Functional\MailerTest::testSendingQueuedMessage
Symfony\Component\Mime\Exception\LogicException: A message must have a text or an HTML part or attachments.

/symfony/src/Symfony/Component/Mime/Email.php:405
/symfony/src/Symfony/Component/Mailer/SentMessage.php:33
/symfony/src/Symfony/Component/Mailer/Transport/AbstractTransport.php:67
/symfony/src/Symfony/Component/Mailer/Mailer.php:42
/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/MailerTest.php:132

How to reproduce
With a the following test, or by sending async templated messages as documented here: https://symfony.com/doc/current/mailer.html#sending-messages-async


class MailerTest extends AbstractWebTestCase
{
    public function testSendingQueuedMessage()
    {
        self::bootKernel(['test_case' => 'Mailer']);

        $testTransport = new class() extends AbstractTransport {
            public function __toString(): string
            {
                return 'dummy://local';
            }

            protected function doSend(SentMessage $message): void
            {
            }
        };

        $mailer = new Mailer($testTransport);

            $message = (new TemplatedEmail())
            ->subject('Test subject')
            ->from('[email protected]')
            ->to('[email protected]')
            ->htmlTemplate('template.html.twig')
        ;

        $mailer->send($message);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions