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
Comment | File | Size | Author |
---|---|---|---|
smtp-from-name.patch | 1.1 KB | mr.baileys | |
Comments
Comment #3
tim-dielsI can confirm this patch is working for the issue described. Had the exact same issue and am now able to send emails. Thx!
Comment #4
borisson_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.
Comment #5
wundo CreditAttribution: wundo at Chuva Inc. commentedTests were fixed in 8.x-1.x, queueing for test again
Comment #6
mr.baileysTests passed, setting back to RTBC
Comment #7
robertom CreditAttribution: robertom at bmeme commentedI receive the following error using the smtp.office365.com SMTP server:
the patch fix also my problem.
TNX
Comment #8
Chris Matthews CreditAttribution: Chris Matthews as a volunteer and at City of Oaks Design commentedThe patch was RTBC'd a year ago and still applies cleanly to 8.x-1.x-dev. Can this be committed?
Comment #9
wundo CreditAttribution: wundo at Chuva Inc. commented