Problem/Motivation

According to MailInterface::mail() :

Returns TRUE if the mail was successfully accepted for delivery, otherwise FALSE.

SMTPMailSystem::mail() breaks the contract and @throws \PHPMailer\PHPMailer\Exception instead.

Steps to reproduce

  • Create a user without setting email and blocked
  • Try to unblock the user

Proposed resolution

Follow the MailInterface::mail() contract and return FALSE when message could not be delivered for whatever reason.

Remaining tasks

  1. Patch - Done!
  2. Review
  3. Commit

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

TBD

Original report

This issue is very similar to #3174535: Invalid address: (cc): PHPMailer Issue. But that issue comes if we login with a different user role. It's working fine when we are with the administrator role and when we turn off the smtp mail system everything will work as expected.

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

Drupal\Core\Entity\EntityStorageException: Invalid address: (to): in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 846 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Steps to reproduce

  • Enable and configure of the SMTP module.
  • Attempt to send a email on via workflow on state transition.

Issue fork smtp-3224734

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

Navodit created an issue. See original summary.

navodit’s picture

Issue summary: View changes
Adamation’s picture

Hi

I get the same issue when using content_moderation_notifications to send the email on a workflow transition.

It'll only send email to the site email address, and attempt to send to additional emails address we get this same error.

Drupal\Core\Entity\EntityStorageException: Invalid address: (to): in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 846 of /var/www/html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

and

Error sending email (from site@emailaddress.com to with reply-to not set).

I think the TO/REPLY-TO format that content_moderation_notifications sends to the SMTP module is the cause, but not sure on a fix.

tr’s picture

Issue tags: -user interface bug
rjhammond’s picture

@Adamation - relating to the "Invalid address" issue when using content_moderation_notification, this patch solved our situation.

The problem occurs when selecting to disable the site email address notification. Hope it helps your case.

rosk0’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Component: User interface » Code
Status: Needs work » Needs review
StatusFileSize
new5.04 KB

We also experienced this exception , however when user account was blocked/unblocked , notification for those operations enabled but the account didn't had email set.

According to MailInterface::mail() :

Returns TRUE if the mail was successfully accepted for delivery, otherwise FALSE.

SMTPMailSystem::mail() breaks the contract and @throws \PHPMailer\PHPMailer\Exception instead.

Attached patch wraps most of the SMTPMailSystem::mail() body into a separate function to catch PHPMailer exceptions. I tried to minimise the change to simplify review.

Status: Needs review » Needs work

The last submitted patch, 6: smtp-3224734-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rosk0’s picture

Title: Invalid address: (to): due to PHPMailer Issue » SMTPMailSystem::mail throws exception "Invalid address: (to)" instead of returning FALSE
Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new6.14 KB
new2.03 KB

In this patch:

  • Update tests to account for new structure
  • Revert unintended switch from list() => []
rosk0’s picture

StatusFileSize
new6.14 KB
new694 bytes

Found an issue in the patch - wrong parameter of the $message used in exception logger.

rosk0’s picture

StatusFileSize
new6.23 KB
new3.59 KB

Re-roll for the latest dev - patch stopped applying after version 1.1.

Status: Needs review » Needs work

The last submitted patch, 10: smtp-3224734-10.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rosk0’s picture

Status: Needs work » Needs review
StatusFileSize
new8.22 KB
new2.44 KB

Fixed tests.

FWIW interdiff between 9 and 10 is not representative - visual patch file comparison gives way better picture than what is generated by interdiff.

ericgsmith made their first commit to this issue’s fork.

ericgsmith’s picture

Moved patch from #12 to MR.

While patch applies cleanly to 8.x-1.3 and all tests on the MR passed, manually testing found a error as 8.x-1.3 introduced additional code that expected logger to be a factory instead of the logger object.

Rather than update the code in debug method I have reverted the change to the constructor logic. I think it could be considered outside the scope of this issue and in recent times keeping the factory as the dependency is preferred.

japerry’s picture

Status: Needs review » Needs work

Made comments on the MR -- there are BC issues and I think we can use reflection instead of needing another public method.

ericgsmith’s picture

Status: Needs work » Needs review

Thanks for the review Jakob - I believe I have implemented all the changes requested.

dtfabio’s picture

Hi ericgsmith,

Thanks for the work, merge request 37 solved the problem for me.

Site Drupal core version 10.2.8, PHP version 8.1.

Greetings,

Fabio

bluegeek9 made their first commit to this issue’s fork.

bluegeek9 changed the visibility of the branch 8.x-1.x to hidden.