Fixed ErrorException during email sending

Affected version
XenForo 2.2.4


New member
Hey, we've been monitoring 3 individual errors appear frequently in the ACP Server Error Log:

ErrorException: Email to failed: [E_WARNING] fwrite(): SSL: Broken pipe src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php:240
Swift_TransportException: Email to 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
Email to 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:
    $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:");
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.

Last edited:


Well-known member
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.

XF Bug Bot

XenForo bug fixer bot
Staff member
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.


XenForo developer
Staff member
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: