Fixed ErrorException during email sending

Affected version
XenForo 2.2.4
Hey, we've been monitoring 3 individual errors appear frequently in the ACP Server Error Log:

Code:
ErrorException: Email to user@example.com failed: [E_WARNING] fwrite(): SSL: Broken pipe src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:240
Code:
Swift_TransportException: Email to user@example.com failed: Expected response code 250 but got code "451", with message "451 4.4.2 Timeout waiting for data from client. " src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383
Code:
Email to user@example.com failed: Expected response code 250 but got code "", with message ""

Our XenForo installation is set-up to send emails to AWS using SMTP. (us-east-1, port 587, TLS encryption)

What appears to have solved this issue is manually closing the Swift_Transport by extending and modifying \XF\Mail\Mailer::send:
PHP:
try
{
    $sent = $transport->send($message, $failedRecipients);
    if (!$sent)
    {
        throw new \Swift_TransportException('Unable to send mail.');
    }
}
catch (\Throwable $e)
{
    if ($this->queue && $allowRetry)
    {
        $this->queue->queueForRetry($message, $queueEntry);
    }

    \XF::logException($e, false, "Email to {$toEmails} failed:");
}
finally
{
    $transport->stop();
}
Note that the finally block takes care of properly closing the transport.

This is obviously just a hot-fix on our side. I'm wondering if not closing the transport is intended, and if there is a proper solution we should be looking for.

Thanks!
 
Last edited:
Interesting. I have been receiving on very scattered occasions, EXACTLY the same messages, using Gmail as my engine. The errors tend to occur in clusters of three or four errors together, and I will go a couple or three weeks with no issues, then the issue crops up again.

I only remember seeing this in XF 2.2.x, not before.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.5).

Change log:
When encountering a SMTP server error while sending email, attempt to establish a fresh connection before sending any further messages.
There may be a delay before changes are rolled out to the XenForo Community.
 
Worth mentioning that this actually ended up being a fair bit more complex because in the process of testing this (and I think this is something that gave me pause in the past when I tried something like this), I ran into a Swiftmailer bug that would essentially break the request if you tried to restart the transport. This is likely specific to the error being triggered, so it won't manifest in all cases.

I've reported that and included a temporary workaround for it within XF:

 
I still continue to get these same errors as the original poster showed, a couple or three times per week. I use gmail as a back-end sender. Doesn't happen every day, but regularly.

Also, and I have noticed this VERY consistently, the error ONLY occurs daily when the system sends out emails via the gmail engine, at 10:22 or 10:23 AM EDT. I do not receive errors at any other time of the day from email.

I am using the current (Patch 2) version of XF 2.2.6, but this has been happening consistently with all versions since at least 2.2.0 or 2.2.1.
 
Same here! I'm getting a couple of this per day as well:
  • ErrorException: Email to xxx failed: [E_WARNING] fwrite(): SSL: Broken pipe
  • src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:223
 
We are getting this. Any help fixing it would be great appreciated.
  • [E_NOTICE] fwrite(): write of 62 bytes failed with errno=32 Broken pipe
  • src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:231
 
We are getting this. Any help fixing it would be great appreciated.
  • [E_NOTICE] fwrite(): write of 62 bytes failed with errno=32 Broken pipe
  • src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:231
You will need to associate your forum user name with your license and then you can post in the customer support forums.
 
@Mike Seems like we're getting this triggered as well on XenForo 2.2.6 Patch 2. I see the issue you opened was closed, but I don't see any commits referenced. Any idea if this was fixed in the library, and if so has it been updated in a later XF release? We have about 30 pages logged of these errors in the last 24 hours
 
Yep, still happens with some regularity using the Gmail engine. I'd say a couple or three times a week. Though I have not seen this error again since updating earlier this week to 2.2.8.
 
Yep, still happens with some regularity using the Gmail engine. I'd say a couple or three times a week. Though I have not seen this error again since updating earlier this week to 2.2.8.
Still getting this error with the gmail engine, about twice a week, in version 2.2.9.
 
i don't use google or smtp. only built in php, this is non stop & tested
2 forums work proper, without any delay.

google have diff restrictions to send email, some countries can not get email, so google is useless for me.
 
  • ErrorException: Email to XXXX from XXXX failed: [E_WARNING] fwrite(): SSL: Broken pipe src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:223
  • Generiert von: Unbekanntes Konto 15 Juni 2022 um 10:40

  • Swift_TransportException: Email to XXXX from XXXX failed: Expected response code 250 but got code "451", with message "451 4.4.2 Timeout waiting for data from client. " src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:459
  • Generiert von: Unbekanntes Konto 15 Juni 2022 um 10:40

4272 Errors in the last 48 hours of this. Is there really nothing i can do? @Chris D
 
guys, did some one find any solution of this problem? i mean brokenpipe error, becauce topic starter provide just switch off the catch error function...
 
guys, did some one find any solution of this problem? i mean brokenpipe error, becauce topic starter provide just switch off the catch error function...
The fix I provided closes the transport in the finally block–it doesn't actually modify the contents of the original try/catch block.

While the XenForo-provided fix significantly reduced the amount of SEL spam we received concerning emails, we ultimately ended up re-implementing our fix as provided in the initial post, as this completely eliminates the error messages while keeping mailing intact, but YMMV.
 
Thanks to @Kirby we (he) found a solution for this. We've installed postfix / sendmail on our server and made postfix using the Amazon SES credentials as smarthost. Since we've changed to this configuration, all errors where gone! 😍
 
Last edited:
Back
Top Bottom