Problem/Motivation

When sending a mail without a mailer transport configured, this results in the following error:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Entity\EntityStorageException: The "" mailer DSN must contain a scheme. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 810 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Symfony\Component\Mailer\Transport->parseDsn() (Line: 113)
Symfony\Component\Mailer\Transport->fromString() (Line: 74)
Symfony\Component\Mailer\Transport::fromDsn() (Line: 135)
Drupal\symfony_mailer\Mailer->doSend() (Line: 91)
Drupal\symfony_mailer\Mailer->Drupal\symfony_mailer\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 92)
Drupal\symfony_mailer\Mailer->send() (Line: 349)
Drupal\symfony_mailer\Email->send() (Line: 74)
Drupal\symfony_mailer_bc\MailManagerReplacement->mail() (Line: 1207)
Drupal\webform\Plugin\WebformHandler\EmailWebformHandler->sendMessage() (Line: 856)
Drupal\webform\Plugin\WebformHandler\EmailWebformHandler->postSave() (Line: 2741)
Drupal\webform\Entity\Webform->invokeHandlers() (Line: 1211)
Drupal\webform\WebformSubmissionStorage->invokeWebformHandlers() (Line: 1119)
Drupal\webform\WebformSubmissionStorage->doPostSave() (Line: 455)
Drupal\Core\Entity\EntityStorageBase->save() (Line: 801)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Line: 982)
Drupal\webform\WebformSubmissionStorage->save() (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 887)
Drupal\webform\Entity\WebformSubmission->save() (Line: 1972)
Drupal\webform\WebformSubmissionForm->save()
call_user_func_array() (Line: 113)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 593)
Drupal\Core\Form\FormBuilder->processForm() (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm() (Line: 1233)
Drupal\webform\Entity\Webform->getSubmissionForm() (Line: 76)
Drupal\webform\Controller\WebformEntityController->addForm()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 57)
Drupal\Core\StackMiddleware\Session->handle() (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 717)
Drupal\Core\DrupalKernel->handle() (Line: 19)
CommentFileSizeAuthor
#11 Screenshot 2021-12-13 at 10.39.00.png34.75 KBjeroent
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

JeroenT created an issue. See original summary.

jeroent’s picture

Status: Active » Needs review
jeroent’s picture

Issue summary: View changes
adamps’s picture

Status: Needs review » Needs work

Thanks looks good I have just one small question

jeroent’s picture

Status: Needs work » Needs review

I reverted the change.

adamps’s picture

Status: Needs review » Needs work

Thanks for the response. I tested the fix (it now needs a reroll which I hacked locally), and I think I found why you added the change you just reverted 😃.

  1. The new code has a fatal error: Typed property Drupal\symfony_mailer\Email::$transportDsn must not be accessed before initialization
  2. The previous code prints an error message The "" mailer DSN must contain a scheme.
  3. Clearly this is a big improvement, however I feel it would be better with clear explanation of the root cause, so in getTransportDsn() if the field is NULL throw an exception something like this Missing email transport: please configure a default. it could maybe even link to the config page??
adamps’s picture

I plan to create a new release soon. If you would be ready to finish off this issue quite quickly then I can wait so that it is included - please let me know if you wish to do that.

jeroent’s picture

I’ll try to update the MR on monday.

adamps’s picture

Great many thanks. I realise my comment #7 was unclear. I think you had it almost right before I reviewed it - sorry😃. I think keep the code to initialise $transportDsn to '', as this ensures that getTransportDsn() is safe to call anytime.

Then the clearer error message in case of the transport being unset would presumably go in Mailer::doSend()?? Anyway I'm sure that once you start coding it, then things will become clear.

jeroent’s picture

Status: Needs work » Needs review
StatusFileSize
new34.75 KB

I updated the MR.

I tried to add something like:

      if (empty($transport_dsn)) {
        throw new \LogicException($this->t('Missing email transport: please configure a <a href=":url">default</a>.', [
          ':url' => Url::fromRoute('entity.mailer_transport.collection')->toString(),
        ]));
      }

but the link doesn't get rendered in the warning message:

So for that reason I created a separate exception.

adamps’s picture

Status: Needs review » Needs work

Thanks, looks good - just one little thing to fix

jeroent’s picture

Status: Needs work » Needs review

I updated the MR.

adamps’s picture

Status: Needs review » Fixed

Thanks

  • AdamPS committed dd876d4 on 1.x authored by JeroenT
    Issue #3252985 by JeroenT, AdamPS: Sending an email without a...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.