swiftmailer | Connection Timed Out

12 posts by 3 authors in: Forums > CMS Builder
Last Post: April 5, 2016   (RSS)

By ross - January 8, 2016

Hi Karls

Thanks for posting and sorry for the delay in getting back to you.

My first impression is you are looking for guidance on troubleshooting Swiftmailer.  Does your host have anymore feedback on why their server is timing out? Can they increase the timeout settings to see if more emails get through?

Let me know any questions or feedback.

Thanks.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By Dave - January 11, 2016

Karls, 

Thanks for the report.  Can you copy and paste the exact error message you are getting?  And how many messages are you sending?  

A couple ideas, I'm wondering if CMSB is sending messages to your mail server faster than it can handle them.  We could test this by checking/logging the delay between attempting to send a message and getting the error.  I could add some code to the specific error returned to show how long it was trying to send the message for.

And if in fact it is a SwiftMailer issue we can work around it or update SwiftMailer, but ideally we'd want to get SwiftMailer updated.

Let me know some more details and we can look into this further.  Thanks!

Dave Edis - Senior Developer
interactivetools.com

By ht1080z - January 25, 2016

Hi Dave,

The error is:

Error: E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out

from the common.php line @trigger_error($e->getMessage(), E_USER_NOTICE);

My email settings:
SMTP server - unsecured connection
Host 127.0.0.1 port 25

Previously i had SSL settings but i cannot make the newsletterBuilder works at all with that, so i changed. Now i get very often this Timed Out error even when the mail is delivered after all.

Thank you,
Karls

By Dave - January 26, 2016

Thanks Karlz, 

Could you try adding this debugging code and then let me know what the new errors are? 

In /lib/common.php search for ### Send Message

Then update the lines in red (or just copy and paste the entire block of code): 

  ### Send Message
  $messagesSent     = 0;
  $failedRecipients = array();
  $errors           = '';
  $sendStartTime    = microtime(true);
  static $totalMessagesSent = 0;
  try {
    $transport->start();  // Catch and report authentication errors early
    $mailer       = Swift_Mailer::newInstance($transport);
    $messagesSent = $mailer->send($message, $failedRecipients);  // $messagesSent adds one for each address on TO: line, CC, BCC, address etc
    $totalMessagesSent += $messagesSent;
  }
  catch (Exception $e) { // catch errors
    $thisMessageTime = sprintf("%0.2f", microtime(true) - $sendStartTime);
    $totalScriptTime = sprintf("%0.2f", microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
    $error           = $e->getMessage() . " (send time: {$thisMessageTime}s, emails sent: {$messagesSent}, total emails sent: {$totalMessagesSent}, total script time: {$totalScriptTime}s)";
    @trigger_error($error, E_USER_NOTICE);   // log error
    $errors .= $e->getMessage() . "\n";      // return error
  }

  // Restore encoding


Let me know what the new errors say.  Thanks!

Dave Edis - Senior Developer
interactivetools.com

By ht1080z - February 19, 2016 - edited: February 19, 2016

Hi Dave,

Thank you for the debug script. I implemented 10days ago and here is some details errors now:

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (send time: 4.01s, emails sent: 0, total emails sent: 3, total script time: 32.76s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (send time: 4.01s, emails sent: 0, total emails sent: 2, total script time: 27.38s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (send time: 4.02s, emails sent: 0, total emails sent: 0, total script time: 14.18s)

E_USER_NOTICE: Expected response code 250 but got code "552", with message "552 Mail rejected by the processing module: Requested action not taken: mailbox unavailable
" (send time: 1.46s, emails sent: 0, total emails sent: 0, total script time: 2.26s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (send time: 4.02s, emails sent: 0, total emails sent: 0, total script time: 9.15s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (send time: 4.01s, emails sent: 0, total emails sent: 7, total script time: 21.52s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (send time: 4.01s, emails sent: 0, total emails sent: 1, total script time: 5.82s)

The errors is always have Filepath /lib/common.php nad line: 1304 (@trigger_error($error, E_USER_NOTICE);)

SMTP settings are attached in screenshot.

Mails are sent in the cases of 99% but errors always triggered.
Unfortunately the newsletterBuilder cannot work with this errors at all.

Thank you,
Karls

Attachments:

SMTP_settings.jpg 78K

By Dave - February 22, 2016

Hi Karlz, 

Do you know what software is used by the SMTP server? 

I've added some more details to the error report message and added the code suggested on stackoverflow.  Can you try this: 

  ### Send Message
  $messagesSent     = 0;
  $failedRecipients = array();
  $errors           = '';
  $sendStartTime    = microtime(true);
  static $totalMessagesSent = 0;
  static $iterations = 0;
  try {
    $iterations++;
    $transport->start();  // Catch and report authentication errors early
    $mailer       = Swift_Mailer::newInstance($transport);
    $messagesSent = $mailer->send($message, $failedRecipients);  // $messagesSent adds one for each address on TO: line, CC, BCC, address etc
    $totalMessagesSent += $messagesSent;
    $mailer->getTransport()->stop(); // http://stackoverflow.com/a/17110512
  }
  catch (Exception $e) { // catch errors
    $mailer->getTransport()->stop(); // http://stackoverflow.com/a/22629213
    $thisMessageTime   = sprintf("%0.2f", microtime(true) - $sendStartTime);
    $totalScriptTime   = sprintf("%0.2f", microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
    $error             = $e->getMessage() . " (total iterations: $iterations, send time: {$thisMessageTime}s, emails sent: {$messagesSent}, total emails sent: {$totalMessagesSent}, total script time: {$totalScriptTime}s)";
    @trigger_error($error, E_USER_NOTICE);   // log error
    $errors .= $e->getMessage() . "\n";      // return error
  }

I still suspect it might be related to the SMTP server, that they're throttling certain connections but we'll keep looking.

Do you know if there's a pattern in the email hostnames that get timeouts?  For example, are they all invalid emails?  Or @aol emails, etc? 

Let me know what you find, thanks!

Dave Edis - Senior Developer
interactivetools.com

By ht1080z - February 23, 2016

Hi Dave,

Thank you for following this up. It is really good to know that i'm not alone with the problem.

I implemented the changes in the common.php and did 2 short test sending mails (test mail from the email templates & password reset request). Strangely i had no new generated error.

Maybe the new $mailer->getTransport()->stop(); function make some difference...

I'll leave the server for a day or two and checking and posting back again later with results.

The server is nginx and AXIGEN Mail-Server 9.0.0 and it is dedicated for only for this project with one cmsBuilder installation.  If you want i can send access to the mail server settings to your mail.

Thank you again,Karls

By ht1080z - February 27, 2016

Hi Dave,

Here is some new records from the error log after  i updated the debug code you sent me.

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (total iterations: 1, send time: 4.16s, emails sent: 0, total emails sent: 0, total script time: 4.26s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (total iterations: 1, send time: 8.03s, emails sent: 0, total emails sent: 0, total script time: 8.06s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (total iterations: 2, send time: 4.15s, emails sent: 0, total emails sent: 1, total script time: 5.99s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (total iterations: 2, send time: 4.94s, emails sent: 0, total emails sent: 1, total script time: 6.56s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (total iterations: 4, send time: 8.01s, emails sent: 0, total emails sent: 2, total script time: 22.06s)

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (total iterations: 2, send time: 5.67s, emails sent: 0, total emails sent: 1, total script time: 12.06s)

Regards,
Karls

By Dave - March 2, 2016

Hi Karlz, 

It looks like on the first error it's timing out on the first try in 4.16 seconds without sending any emails:

E_USER_NOTICE: Connection to 127.0.0.1:25 Timed Out (total iterations: 1, send time: 4.16s, emails sent: 0, total emails sent: 0, total script time: 4.26s)

The "Connection to" error is thrown in two places in /cmsb/3rdParty/SwiftMailer5/classes/Swift/Transport\StreamBuffer.php after checking the PHP function stream_get_meta_data() to determine if the connection has timed out.

So it looks like PHP is indicating the connection timed out after approx 4 seconds while connecting to the remote server on the very first try sending an email.

Here's some things you could try moving forward:

  • Provide your host with the exact date and time of that error and ask them to check the server mailers logs to see what error were reported (it could be an anti-spam features that is timing out connections it thinks are suspicious).
  • Try adding " ... To: {$options['to']}, ... " to the error string to see if there's a pattern in which emails are receiving timeouts (such as all emails from a specific domain).
  • Find out if the server mailer software is being restarted frequently.  If there was something like a cron that killed and restarted the mailer every 10 minutes (to solve some other problem) that might create random timeouts like this.
  • Try using a 3rd party SMTP sending service such as https://www.mandrill.com/
  • Try configuring CMSB to use PHP's built in mail() function if you haven't already done this. 

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com