Problem/Motivation

Background in #2944822: Error "554 Transaction failed: Missing '<' " when using the SMTP module and AWS SES.

When MailManagerInterface::mail() is called with a $reply-parameter in the form "Friendly Name <email@example.com>", the actual header that is sent to the SMTP server is malformed:

From: Umami Food Magazine <Friendly Name <email@example.com>>

Amazon SES returns

554 Transaction failed: Missing '<'

The MailManagerInterface::mail() documentation seems to indicate that calling it with a "full email address" is valid (as opposed to using only raw email addresses), and the fact that this works with other Mail plugins further points to this being a bug in the SMTP module.

Proposed resolution

\Drupal\smtp\Plugin\Mail\SMTPMailSystem::mail() assumes that $reply does not contain a full name. This assumption is incorrect. Patch attached extracts both the raw email address and the friendly name from the $reply parameter. The full name is used if it is not overridden via the smtp_fromname setting. If the full name is not passed via $reply, and not set via smtp_fromname, the site name is still used.

Remaining tasks

Review & Commit.

User interface changes

None.

API changes

None

Data model changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mr.baileys created an issue. See original summary.

Status: Needs review » Needs work

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

tim-diels’s picture

I can confirm this patch is working for the issue described. Had the exact same issue and am now able to send emails. Thx!

borisson_’s picture

Status: Needs work » Reviewed & tested by the community

This failing test is unrelated to this, that failure is in all of the tests: https://www.drupal.org/node/35189/qa

PHP Parse error: syntax error, unexpected '?' in /var/www/html/modules/contrib/smtp/tests/src/Unit/Plugin/Mail/SMTPMailSystemTest.php on line 123

That should probably be fixed in #2808081: Automated tests for the SMTP module

The patch looks very good though, and it does fix the problem.

wundo’s picture

Status: Reviewed & tested by the community » Needs review

Tests were fixed in 8.x-1.x, queueing for test again

mr.baileys’s picture

Status: Needs review » Reviewed & tested by the community

Tests passed, setting back to RTBC

robertom’s picture

I receive the following error using the smtp.office365.com SMTP server:

Error sending e-mail from Name <email@example.com> to email2@example.com: SMTP Error: Data not accepted.<p>SMTP server error: 5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:24180000, 17.43559:0000000094000000000000000100000000000000, 20.52176:140FB7840A0010101F009031, 20.50032:140FB7847A1710101F001E31, 0.35180:59390000, 255.23226:0A00B231, 255.27962:0A000000, 255.27962:0E000000, 255.31418:D73A0000, 16.55847:DE000000, 17.43559:0000000068010000000000000100000000000000, 20.52176:140FB7840A001010E</p> 

the patch fix also my problem.

TNX

Chris Matthews’s picture

The patch was RTBC'd a year ago and still applies cleanly to 8.x-1.x-dev. Can this be committed?

git apply -v smtp-from-name.patch
Checking patch src/Plugin/Mail/SMTPMailSystem.php...
Applied patch src/Plugin/Mail/SMTPMailSystem.php cleanly.
wundo’s picture

Status: Reviewed & tested by the community » Fixed

  • wundo committed 41bc78b on 8.x-1.x authored by mr.baileys
    Issue #2984144 by mr.baileys, tim-diels, borisson_, wundo, Chris...

Status: Fixed » Closed (fixed)

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