"$emailAddress" must be a valid email address.

Created on 30 May 2025, 4 days ago

Problem/Motivation

When the site name contains characters that require encoding, an error occurs during email sending.

The error message:

SendGrid\Exception\TypeException: "$emailAddress" must be a valid email address. Got: =?utf-8?Q?=E8=BF=99=E6=98=AF=E4=B8=80=E4=B8=AA?= =?utf-8?Q?=E6=B5=8B=E8=AF=95=E7=BD=91=E7=AB=99?= <xxxx@example.com> in SendGrid\Helper\Assert::email() (line 68 of /var/www/html/vendor/fastglass/sendgrid/src/Helper/Assert.php).
SendGrid\Mail\EmailAddress->setEmailAddress() (Line: 54)
SendGrid\Mail\EmailAddress->__construct() (Line: 276)
Drupal\sendgrid_integration\Plugin\Mail\SendGridMail->doMail() (Line: 150)
Drupal\sendgrid_integration\Plugin\Mail\SendGridMail->mail() (Line: 50)
Drupal\mailsystem\Adapter->mail() (Line: 308)
Drupal\Core\Mail\MailManager->doMail() (Line: 181)
Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 180)
Drupal\Core\Mail\MailManager->mail() (Line: 70)
Drupal\mailsystem\MailsystemManager->mail() (Line: 168)
Drupal\sendgrid_integration\Form\SendGridTestForm->submitForm()
call_user_func_array() (Line: 105)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers() (Line: 43)
Drupal\Core\Form\FormSubmitter->doSubmitForm() (Line: 589)
Drupal\Core\Form\FormBuilder->processForm() (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

  1. Install Drupal core 11.1.6 and SendGrid Integration 2.3.0, and configure it to send emails via SendGrid.
  2. Go to /admin/config/system/site-information and set the Site name to "这是一个测试网站".
  3. Go to /admin/config/services/sendgrid/test and send a test email.

Proposed resolution

SENDGRID_INTEGRATION_EMAIL_REGEX = '/^\s*"?(.+?)"?\s*<\s*([^>]+)\s*>$/' does not appear to take into account newline characters that may be present in an encoded site name.

I think it would be better to modify SENDGRID_INTEGRATION_EMAIL_REGEX so that the dot metacharacter also matches newline characters.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇯🇵Japan wakaiakari

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024