Description
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
- create one simple twig template for html part of email, for example:
# templates/email/hello.html.twig
<p>Hi {{ email.to }}!</p>
- create a console command and inject Mailer in constructor
private $mailer;
public function __construct(MailerInterface $mailer)
{
$this->mailer = $mailer;
parent::__construct();
}
- 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);
- 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