Details
-
Bug
-
Resolution: Unresolved
-
Low
-
None
-
None
-
None
-
None
-
tested in eZ Publish 4.x versions (4.5 and 4.7 for sure)
Description
If eZ Publish is configured to send email notifications via MTA using Amazon Simple Email Service (SES), MTA's logs are filled with following error messages:
Sep 30 09:06:46 ip-10-127-233-125 postfix/smtp[25753]: 75AE25032C: to=<xxx@example.com>, relay=email-smtp.us-north-1.amazonaws.com[51.353.111.111]:25, delay=1.1, delays=0.06/0/0.68/0.4, dsn=5.0.0, status=bounced (host email-smtp.us-north-1.amazonaws.com[51.353.111.111] said: 554 Transaction failed: Empty required header 'To'. (in reply to end of DATA command))
Indeed, header "To:" of the email is empty:
From: noreply@example.com To: Bcc: xxx@example.com Subject: New comment - nacaa MIME-Version: 1.0 User-Agent: eZ Components Date: Fri, 30 Sep 2015 18:05:51 +0200 Message-Id: <2015093018182551.4541.0@example.com> Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit
In fact, "to" field is not set in eZMailNotificationTransport class:
kernel/classes/notification/ezmailnotificationtransport.php
37 class eZMailNotificationTransport extends eZNotificationTransport 38 { ... 47 function send( $addressList = array(), $subject, $body, $transportData = null, $parameters = array() ) 48 { ... 66 foreach ( $addressList as $addressItem ) 67 { 68 $mail->extractEmail( $addressItem, $email, $name ); 69 $mail->addBcc( $email, $name ); 70 } 71 $mail->setSender( $emailSender ); 72 $mail->setSubject( $subject ); 73 $mail->setBody( $body ); ...
Tracking the issue further, I found out that the core of the issue is in ezcMail class of eZ Components bundled with eZ Publish 4.x versions in line 350. There is condition testing whether $this->to member is not null, while it supposed to test whether it is not an empty array:
lib/ezc/Mail/src/mail.php
... 123 public function __construct( ezcMailOptions $options = null ) 124 { 125 parent::__construct(); 126 127 $this->properties['from'] = null; 128 $this->properties['to'] = array(); 129 $this->properties['cc'] = array(); 130 $this->properties['bcc'] = array(); 131 $this->properties['subject'] = null; ... 226 public function __get( $name ) 227 { 228 switch ( $name ) 229 { 230 case 'to': 231 case 'cc': 232 case 'bcc': 233 return (array) $this->properties[$name]; ... 342 public function generateHeaders() 343 { ... 350 if ( $this->to !== null ) 351 { 352 $this->setHeader( "To", ezcMailTools::composeEmailAddresses( $this->to ) ); 353 } ...
The change below fixes the issue:
--- lib/ezc/Mail/src/mail.php_prev 2015-09-30 14:27:55.186248548 +0000 +++ lib/ezc/Mail/src/mail.php 2015-09-30 14:28:03.949150360 +0000 @@ -347,7 +347,7 @@ $this->setHeader( "From", ezcMailTools::composeEmailAddress( $this->from ) ); } - if ( $this->to !== null ) + if ( !empty( $this->to ) ) { $this->setHeader( "To", ezcMailTools::composeEmailAddresses( $this->to ) ); }