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

[Mailer] \Symfony\Component\Mailer\Event\MessageEvent never consumed #31449

Copy link
Copy link
Closed
@Perf

Description

@Perf
Issue body actions

Symfony version(s) affected: 4.3.0-BETA1

Description
When sending email using a new symfony/mailer component an event \Symfony\Component\Mailer\Event\MessageEvent us dispatched.
Mailer component has two subscribers for this event:
\Symfony\Component\Mailer\EventListener\MessageListener
\Symfony\Component\Mailer\EventListener\EnvelopeListener
but non of them are fired in case of an event.

Command bin/console de:ev also doesn't shows these listeners.

How to reproduce

  1. create one simple twig template for html part of email, for example:
# templates/email/hello.html.twig
<p>Hi {{ email.to }}!</p>
  1. create a console command and inject Mailer in constructor
    private $mailer;

    public function __construct(MailerInterface $mailer)
    {
        $this->mailer = $mailer;
        parent::__construct();
    }
  1. put in execute method something like:
        $email = new TemplatedEmail();
        $email
            ->from('no-reply@domain.com')
            ->to('me@domain.com')
            ->subject('Test email message')
            ->htmlTemplate('email/hello.html.twig')
            ;

        $this->mailer->send($email);
  1. get an Exception

In HandleMessageMiddleware.php line 82:
A message must have a text and/or an HTML part.
In Email.php line 427:
A message must have a text and/or an HTML part.

This exception raised because \Symfony\Component\Mailer\EventListener\MessageListener was not fired.

Possible Solution
¯\_(ツ)_/¯

Additional context
symfony/messenger is installed with default configuration
symfony/swiftmailer-bundle is not installed

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

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