Problem/Motivation
D8.9.3
After updating SM from 1.0-beta1 to 2.0-beta2, it get an error when sending email via Simplenews module :
The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Swift_Mime_Headers_UnstructuredHeader::getAddresses() in Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message() (line 413 of modules/contrib/swiftmailer/src/Utility/Conversion.php).Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message(Object) (Line: 337)
Drupal\swiftmailer\Plugin\Mail\SwiftMailer->mail(Array) (Line: 50)
Drupal\mailsystem\Adapter->mail(Array) (Line: 307)
Drupal\Core\Mail\MailManager->doMail('simplenews', 'test', 'bpelvillain@gmail.com', 'fr', Array, '"=?UTF-8?B?Q29vcMOpcmF0aXZlcyBkJ0FjdGl2aXTDqXMgZXQgZCdFbXBsb2kgZW4gSWxsZS0=?=
=?UTF-8?B?ZXQtVmlsYWluZQ==?=" ', 1) (Line: 179)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 180)
Drupal\Core\Mail\MailManager->mail('simplenews', 'test', 'bpelvillain@gmail.com', 'fr', Array, '"=?UTF-8?B?Q29vcMOpcmF0aXZlcyBkJ0FjdGl2aXTDqXMgZXQgZCdFbXBsb2kgZW4gSWxsZS0=?=
=?UTF-8?B?ZXQtVmlsYWluZQ==?=" ', 1) (Line: 70)
Drupal\mailsystem\MailsystemManager->mail('simplenews', 'test', 'bpelvillain@gmail.com', 'fr', Array, '"=?UTF-8?B?Q29vcMOpcmF0aXZlcyBkJ0FjdGl2aXTDqXMgZXQgZCdFbXBsb2kgZW4gSWxsZS0=?=
=?UTF-8?B?ZXQtVmlsYWluZQ==?=" ') (Line: 332)
Drupal\simplenews\Mail\Mailer->sendMail(Object) (Line: 388)
Drupal\simplenews\Mail\Mailer->sendTest(Object, Array) (Line: 211)
Drupal\simplenews\Form\NodeTabForm->submitTestMail(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('simplenews_node_tab', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
This issue does'nt appear when testing via /admin/config/swiftmailer/test.
Steps to reproduce
- Install and configure Simplenews.
- Create a content from 'Newsletter issue' content type.
- From this content, click on Newsletter tab and send a test.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | swiftmailer-3167898-03.patch | 2.02 KB | Ruedische |
Issue fork swiftmailer-3167898
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
Comment #2
geek-merlinThanks for filing this issue and providing the backtrace!
I guess this happens when from or to field contains nonvalid mail addresses.
@brulain can you confirm this?
If that's true, in these lines we have to check for
instanceof \Swift_Mime_Headers_MailboxHeaderbefore we call the method.Patch appreciated.
Comment #3
Ruedische commentedA working patch is applied.
Comment #4
brulain commentedThanks a lot guys !
The patch #3 fixes this issue.
Comment #5
geek-merlinHint: After uploading a patch set status to needs-review. And always check current dev. Descriptive title helps too ;-)
Thanks for rolling and testing a patch!
1. Alas, we not have to check $headers (which is always instanceof Swift_Mime_SimpleHeaderSet), but
$headers->get('from')/$headers->get('to').2. Can you please provide the from/too headers so this can be reproduced.
3. We have to decide how to handle that error. I'm not sure how the rest of the module handles this. But just hiding the problem without even logging is not an option.
4. Whatever we decide, we need tests. (and therefore 2))
Comment #6
brulain commentedHere are the headers of a newsletter issue (test):
Comment #7
brulain commentedI have changed the From headers and rolled back the patch: no more error when sending a (test) newsletter issue.
Comment #8
geek-merlin@brulain: Do you have an explanation for this? I do not grok that utf8-encoding stuff in "from".
Comment #9
brulain commented@geek-merlin: no explanation.
The original From value in Simplenews settings was: Coopérative d'activité et d'emploi - Ile et Vilaine
I changed it to: Élan créateur
Comment #10
geek-merlin@brulain: So it looks like all these 'from' headers are invalid as email address, so it's no wonder sending fails.
So maybe we should just throw a descripive exception in such case.
Comment #11
brulain commented@geek-merlin: In fact, I have only changed the value of the "From name" field in Simplenews settings (/admin/config/services/simplenews/manage/default).
Comment #12
shelaneI am getting the same error simply trying to use the test method on
/admin/config/swiftmailer/testwith my own email address. After applying the patch, I no longer got that error, but I got another instead:Comment #13
shelaneOk, my issue turned out to be that I was testing a site locally that did not have the site from name or email set. Once I set that, it worked without the patch.
Comment #14
mingsongI came across this issue.
Steps to reproduce this issue:
1. Enable the Swiftmailer module (8.x-2.0-beta1).
2. Choose the Swiftmailer as the Sender at Configure the Mail System page (/admin/config/system/mailsystem)
3. Enable the Webform module if it hasn't.
4. Create a new Webform in which there is a plain text field called 'From'.
5. Create a email handler for this webform.
6. Choose the input from the 'From' field created from step 4 as the from address of the email sent out by this webform.
7. Go to the webform created and fill in an invalid email address for the 'From' text field. For example: 'My email'.
8. Submit this webform.
Once submitting this form, the white screen with the same PHP error message shows up.
Updated:
Patch at #3 avoids this error from happening.
Comment #15
AnnaE1990 commentedswiftmailer-3167898-03.patch
i have some issue 2 websites witch the same module in one when i use mail system sender plugin swift mailer (simplenews) its work fine.
On second websites i have:
"The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Swift_Mime_Headers_UnstructuredHeader::getAddresses() in Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message() (line 413 of modules/swiftmailer/src/Utility/Conversion.php)."
This patch is applied.
i use modules:
Mail System 8.x-4.3
Swift Mailer 8.x-2.0
simplenews 3.0.0-alpha1
And report from website:
"Error: Call to undefined method Swift_Mime_Headers_UnstructuredHeader::getAddresses() w Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message() (linia 413 w /home/e-jankowska/websites/pzg/modules/swiftmailer/src/Utility/Conversion.php)
#0 /home/e-jankowska/websites/pzg/modules/swiftmailer/src/Plugin/Mail/SwiftMailer.php(337): Drupal\swiftmailer\Utility\Conversion::swiftmailer_filter_message(Object(Swift_Message))
#1 /home/e-jankowska/websites/pzg/modules/mailsystem/src/Adapter.php(50): Drupal\swiftmailer\Plugin\Mail\SwiftMailer->mail(Array)
#2 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Mail/MailManager.php(311): Drupal\mailsystem\Adapter->mail(Array)
#3 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Mail/MailManager.php(180): Drupal\Core\Mail\MailManager->doMail('simplenews', 'test', 'pomoc@e-jankows...', 'pl', Array, '"=?UTF-8?B?IFfF...', true)
#4 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Render/Renderer.php(578): Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}()
#5 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Mail/MailManager.php(181): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#6 /home/e-jankowska/websites/pzg/modules/mailsystem/src/MailsystemManager.php(70): Drupal\Core\Mail\MailManager->mail('simplenews', 'test', 'pomoc@e-jankows...', 'pl', Array, '"=?UTF-8?B?IFfF...', true)
#7 /home/e-jankowska/websites/pzg/modules/contrib/simplenews/src/Mail/Mailer.php(332): Drupal\mailsystem\MailsystemManager->mail('simplenews', 'test', 'pomoc@e-jankows...', 'pl', Array, '"=?UTF-8?B?IFfF...')
#8 /home/e-jankowska/websites/pzg/modules/contrib/simplenews/src/Mail/Mailer.php(388): Drupal\simplenews\Mail\Mailer->sendMail(Object(Drupal\simplenews\Mail\MailEntity))
#9 /home/e-jankowska/websites/pzg/modules/contrib/simplenews/src/Form/NodeTabForm.php(211): Drupal\simplenews\Mail\Mailer->sendTest(Object(Drupal\node\Entity\Node), Array)
#10 [internal function]: Drupal\simplenews\Form\NodeTabForm->submitTestMail(Array, Object(Drupal\Core\Form\FormState))
#11 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Form/FormSubmitter.php(113): call_user_func_array(Array, Array)
#12 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Form/FormSubmitter.php(51): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#13 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Form/FormBuilder.php(593): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#14 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Form/FormBuilder.php(321): Drupal\Core\Form\FormBuilder->processForm('simplenews_node...', Array, Object(Drupal\Core\Form\FormState))
#15 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\simplenews\Form\NodeTabForm), Object(Drupal\Core\Form\FormState))
#16 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#17 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#18 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/Render/Renderer.php(578): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#19 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#20 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#21 /home/e-jankowska/websites/pzg/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#22 /home/e-jankowska/websites/pzg/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#23 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /home/e-jankowska/websites/pzg/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /home/e-jankowska/websites/pzg/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /home/e-jankowska/websites/pzg/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /home/e-jankowska/websites/pzg/core/lib/Drupal/Core/DrupalKernel.php(716): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /home/e-jankowska/websites/pzg/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#32 {main}"
Comment #16
g-brodieiI've encountered the same issue today while upgrading our site from Drupal 9.1 to 9.2.
We're able to reproduce the issue with the following modules.
We believe this was due to the issue in $mailbox->getBodyAsString() after the Mime change usage of Symfony in
https://www.drupal.org/project/drupal/issues/84883#comment-14052174
Comment #17
g-brodieiThe regex pattern used in swiftmailer_is_mailbox_header doesn't match the current Q-encoding format, therefore returning false, not setting the headerType correctly in line 248 of web/modules/contrib/swiftmailer/src/Plugin/Mail/SwiftMailer.php.
should be "mailbox", instead "text" was returned.
Comment #18
g-brodieiA patch was provided at #3219705-13: Call to undefined method Swift_Mime_Headers_UnstructuredHeader::getAddresses() aiming to fix the q-encoding issue after upgrading to 9.2.
If that patch works for this issue, hopefully we can close it. (finger crossed)
Comment #19
berdirI think this can happen separately from line break problems. We just had a case where this happened for a webform because the client selected a wrong field as sender that was not actually an e-mail.
So IMHO this fix/issue still makes sense. Not sure if the fix is correct though and just silently ignore that specific thing. Maybe the mail shouldn't be sent or with a fallback + a log message?
Comment #20
adamps commentedIf I understand correctly, this issue is about this: the module throws an exception if the addresses are malformed.
I don't really understand why this is considered a bug. I guess we could ask improve the message to make the cause more obvious.
However this module is minimally supported now due to swiftmailer library soon becoming unsupported so I propose to commit major bug fixes only.
Comment #21
berdir> If I understand correctly, this issue is about this: the module throws an exception if the addresses are malformed.
To slightly reword this:
the module throws a confusing, unhelpful exception if the addresses are malformed.
It would already be much better if incorrect user input would result in a clear, helpful exception message (E-mail address "foo" is invalid).
Mail plugins are not expected to throw an exception, that would need to be documented on https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Mail%21Ma... IMHO, similar to other interfaces to have documented exceptions. Then the mail manager or mail send code would be responsible to catch and deal with that exception, but that's now how the drupal mail API works. it has a return status instead, so IMHO, this problem should be caught with a helpful error message and the corresponding status returned.
Comment #22
adamps commentedThanks @Berdir #21 sounds fine to me as an idea - I updated the title to match