Loading src/Email.php +1 −2 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Render\RendererInterface; use Drupal\symfony_mailer\Processor\EmailProcessorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Mailer\Transport\TransportInterface; use Symfony\Component\Mime\Email as SymfonyEmail; class Email implements UnrenderedEmailInterface, RenderedEmailInterface { Loading Loading @@ -55,7 +54,7 @@ class Email implements UnrenderedEmailInterface, RenderedEmailInterface { /** * The mail transport DSN. */ protected string $transportDsn; protected string $transportDsn = ''; /** * Constructs the Email object. Loading src/Exception/MissingTransportException.php 0 → 100644 +10 −0 Original line number Diff line number Diff line <?php namespace Drupal\symfony_mailer\Exception; /** * Error thrown when no email transport is configured. */ class MissingTransportException extends \Exception { } src/Mailer.php +17 −3 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationManager; use Drupal\Core\Url; use Drupal\symfony_mailer\Exception\MissingTransportException; use Symfony\Component\Mailer\Exception\RuntimeException; use Symfony\Component\Mailer\Mailer as SymfonyMailer; use Symfony\Component\Mailer\Transport; Loading Loading @@ -131,15 +133,27 @@ class Mailer implements MailerInterface { } $this->invokeAll('pre_send', $rendered_email); try { // Send. $transport = Transport::fromDsn($rendered_email->getTransportDsn()); $transport_dsn = $rendered_email->getTransportDsn(); if (empty($transport_dsn)) { throw new MissingTransportException('Missing email transport: please configure a default.'); } $transport = Transport::fromDsn($transport_dsn); $mailer = new SymfonyMailer($transport, NULL, $this->dispatcher); try { //ksm($rendered_email, $rendered_email->getInner()->getHeaders()); $mailer->send($rendered_email->getInner()); $result = TRUE; } catch (MissingTransportException $e) { \Drupal::messenger()->addWarning($this->t('Missing email transport: please configure a <a href=":url">default</a>.', [ ':url' => Url::fromRoute('entity.mailer_transport.collection')->toString(), ])); $result = FALSE; } catch (RuntimeException $e) { // @todo Log exception, print user-focused message. \Drupal::messenger()->addWarning($e->getMessage()); Loading Loading
src/Email.php +1 −2 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Render\RendererInterface; use Drupal\symfony_mailer\Processor\EmailProcessorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Mailer\Transport\TransportInterface; use Symfony\Component\Mime\Email as SymfonyEmail; class Email implements UnrenderedEmailInterface, RenderedEmailInterface { Loading Loading @@ -55,7 +54,7 @@ class Email implements UnrenderedEmailInterface, RenderedEmailInterface { /** * The mail transport DSN. */ protected string $transportDsn; protected string $transportDsn = ''; /** * Constructs the Email object. Loading
src/Exception/MissingTransportException.php 0 → 100644 +10 −0 Original line number Diff line number Diff line <?php namespace Drupal\symfony_mailer\Exception; /** * Error thrown when no email transport is configured. */ class MissingTransportException extends \Exception { }
src/Mailer.php +17 −3 Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationManager; use Drupal\Core\Url; use Drupal\symfony_mailer\Exception\MissingTransportException; use Symfony\Component\Mailer\Exception\RuntimeException; use Symfony\Component\Mailer\Mailer as SymfonyMailer; use Symfony\Component\Mailer\Transport; Loading Loading @@ -131,15 +133,27 @@ class Mailer implements MailerInterface { } $this->invokeAll('pre_send', $rendered_email); try { // Send. $transport = Transport::fromDsn($rendered_email->getTransportDsn()); $transport_dsn = $rendered_email->getTransportDsn(); if (empty($transport_dsn)) { throw new MissingTransportException('Missing email transport: please configure a default.'); } $transport = Transport::fromDsn($transport_dsn); $mailer = new SymfonyMailer($transport, NULL, $this->dispatcher); try { //ksm($rendered_email, $rendered_email->getInner()->getHeaders()); $mailer->send($rendered_email->getInner()); $result = TRUE; } catch (MissingTransportException $e) { \Drupal::messenger()->addWarning($this->t('Missing email transport: please configure a <a href=":url">default</a>.', [ ':url' => Url::fromRoute('entity.mailer_transport.collection')->toString(), ])); $result = FALSE; } catch (RuntimeException $e) { // @todo Log exception, print user-focused message. \Drupal::messenger()->addWarning($e->getMessage()); Loading