Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Description
Symfony version(s) affected: 4.3.0-BETA1
Description
When sending email using a newsymfony/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.
Commandbin/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;publicfunction__construct(MailerInterface$mailer) {$this->mailer =$mailer;parent::__construct(); }
- put in
executemethod something like:
$email =newTemplatedEmail();$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 contextsymfony/messenger is installed with default configurationsymfony/swiftmailer-bundle is not installed