Mail stopped working - Error:SMTP connect() failed.

Hello,

I have a problem with sending mails from my SuiteCRM system. It has suddenly stopped working in the middle of last month. I’m using a mail from office365. It stopped working out of the blue. I have tested with multiply mails and also gmails.

When testing the mail, it shows the following error message:
Error:SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

The log show the following:
Tue Nov 7 13:19:03 2017 [12972][1][FATAL] SugarPHPMailer encountered an error: An outgoing mail server is not configured to send emails. Please configure an outgoing mail server or select an outgoing mail server for the mail account that you are using in Settings >> Mail Account.
Tue Nov 7 13:19:03 2017 [12972][1][FATAL] SugarPHPMailer encountered an error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Does anybody have a solution for this?

I am working on this issue now and I hope to get some improvements into the next version.

Are you comfortable editing a few PHP files? If so I can give you code to start debugging your issue right now.

Sure. I can do that.
Thank you!

This is not a proper fix, it’s just a temporary debugging procedure.

  1. In file include/SugarPHPMailer.php, completely remove the current function called smtpConnect.

  2. Add all the code below, which has a new smtpConnect function, a new variable, and a new method wrapper (send).


public $phpMailerFullLog='';

public function send() {
   $GLOBALS['log']->fatal("------------ Entering SugarMailer send");
        $this->phpMailerFullLog='';
//Use these to override some fields for tests:
//$this->From = 'me@here.com';
//$this->Sender = 'me@here.com';
//$this->Password='wrong';
//$this->FromName = 'My Name';
        $GLOBALS['log']->fatal("PHPMailer Send Function override: { FromName: $this->FromName From: $this->From Host: $this->Host UserName: $this->Username }");

        $ret = parent::send();

$line = strtok($this->phpMailerFullLog, "\n");

while ($line !== false) {
        $GLOBALS['log']->fatal("smtp send: { $line }");
    $line = strtok( "\n" );
}
   $GLOBALS['log']->fatal("------------ Exiting SugarMailer send");

        return $ret;
     }



    public function smtpConnect($options = array())
    {
   $GLOBALS['log']->fatal("------------ Entering smtpConnect");
   $this->phpMailerFullLog='';
   $phpMailerExceptionMsg='';
   try {
        $saveExceptionsState = $this->exceptions;
        $this->exceptions = true;
        $this->Debugoutput = function($str, $level) {
             $this->phpMailerFullLog .= "$level: $str\n";
        };

        $this->SMTPDebug = 3;
        //$mail->Debugoutput='html';

        $connection = parent::smtpConnect();
        $this->exceptions =  $saveExceptionsState;
     }
     catch (Exception $e) {
        $phpMailerExceptionMsg=$e->getMessage();
        if ($phpMailerExceptionMsg) {
           $GLOBALS['log']->fatal("Internal PHPMailer smtpConnect Exception: { $phpMailerExceptionMsg } ---------------");
        }
     }
     $line = strtok($this->phpMailerFullLog, "\n");

     while ($line !== false) {
        $GLOBALS['log']->fatal("smtpConnect: { $line }");
        $line = strtok( "\n" );
     }
        if (!$connection) {
            global $app_strings;
            if (isset($this->oe) && $this->oe->type === 'system') {
                $this->setError($app_strings['LBL_EMAIL_INVALID_SYSTEM_OUTBOUND'].' '.$phpMailerExceptionMsg);
            } else {
                $this->setError($app_strings['LBL_EMAIL_INVALID_PERSONAL_OUTBOUND'].' '.$phpMailerExceptionMsg);
            } // else
        }
   $GLOBALS['log']->fatal("------------ Exiting smtpConnect");

        return $connection;
   }

Now try sending your test emails and check your suitecrm.log (you can grep it for FATAL errors only).

Also read this Issue to see if that is the problem you’re getting.

I have now tried the changes you posted, and got the following error messages:
The “removed” has been changed by me from the logs.


Thu Nov  9 07:49:58 2017 [21464][1][FATAL] ------------ Entering SugarMailer send
Thu Nov  9 07:49:58 2017 [21464][1][FATAL] PHPMailer Send Function override: { FromName: removed From: removed Host: smtp.office365.com UserName: removed }
Thu Nov  9 07:49:58 2017 [21464][1][FATAL] ------------ Entering smtpConnect
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtpConnect: { 3: Connection: opening to smtp.office365.com:587, timeout=300, options=array ( }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtpConnect: { ) }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtpConnect: { 3: Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known [/var/www/html/include/phpmailer/class.smtp.php line 299] }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtpConnect: { 3: Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.office365.com:587 (php_network_getaddresses: getaddrinfo failed: Name or service not known) [/var/www/html/include/phpmailer/class.smtp.php line 299] }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtpConnect: { 1: SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0) }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] SugarPHPMailer encountered an error: An outgoing mail server is not configured to send emails. Please configure an outgoing mail server or select an outgoing mail server for the mail account that you are using in Settings >> Mail Account. 
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] ------------ Exiting smtpConnect
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] SugarPHPMailer encountered an error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtp send: { 3: Connection: opening to smtp.office365.com:587, timeout=300, options=array ( }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtp send: { ) }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtp send: { 3: Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known [/var/www/html/include/phpmailer/class.smtp.php line 299] }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtp send: { 3: Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.office365.com:587 (php_network_getaddresses: getaddrinfo failed: Name or service not known) [/var/www/html/include/phpmailer/class.smtp.php line 299] }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtp send: { 1: SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0) }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] smtp send: { 3: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting }
Thu Nov  9 07:50:39 2017 [21464][1][FATAL] ------------ Exiting SugarMailer send

I’ve never seen that particular error.

It looks like your host names aren’t resolving in DNS. Maybe you can check your DNS configuration, your /etc/hosts file, and make sure PHP can reach your server by name.

A simple test to see if that’s really the problem: to change your server name from smtp.office365.com to whater IP address you get from “nslookup smtp.office365.com

It was the DNS. It’s fixed now.
Thank you very much for the help. Without the code, I wouldn’t have known what the problem could be.

Yeah, I’m glad it helped. We have to get that into the product.

A word of warning, though: in its current form, when you connect to the SMTP server, your logs will include the full SMTP debugging log.

This contains usernames and passwords, which look encrypted but are not, they are merely BASE64 encoded, which anyone can decode easily. So the above code is NOT for production, and is not secure to leave in place - make sure you deactivate it.

I would say so. It was very useful in my case.

I have removed it again from the file. Thank you.

Thu Dec 14 14:28:04 2017 [165228][1][FATAL] ------------ Entering SugarMailer send
Thu Dec 14 14:28:04 2017 [165228][1][FATAL] PHPMailer Send Function override: { FromName: SuiteCRM From: do_not_reply@lindexcrm.com Host: smtp.gmail.com UserName: lindexsuite@gmail.com }
Thu Dec 14 14:28:04 2017 [165228][1][FATAL] ------------ Entering smtpConnect
Thu Dec 14 14:28:04 2017 [165228][1][FATAL] Internal PHPMailer smtpConnect Exception: { Extension missing: openssl } ---------------
Thu Dec 14 14:28:04 2017 [165228][1][FATAL] SugarPHPMailer encountered an error: An outgoing mail server is not configured to send emails. Please configure an outgoing mail server or select an outgoing mail server for the mail account that you are using in Settings >> Mail Account. Extension missing: openssl
Thu Dec 14 14:28:04 2017 [165228][1][FATAL] ------------ Exiting smtpConnect
Thu Dec 14 14:28:04 2017 [165228][1][FATAL] SugarPHPMailer encountered an error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Thu Dec 14 14:28:04 2017 [165228][1][FATAL] SugarPHPMailer encountered an error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Thu Dec 14 14:28:04 2017 [165228][1][FATAL] Exception in Controller: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

This is what I’ve got in log file but I changed the line in php.ini and restart apache but still this problem.

If you got any idea what is the problem that could help me, I would be glad to hear it.

Thanks for your time.

Best regards,
Meriton.

You need the openssl extension in PHP, try Googling for how to install it. This is probably only required because of your security options in that account (SSL).

I’ve got the extension file. You can see it in this photo https://imgur.com/1ma8qok.

I don’t know how it works on Windows, but you probably need to tell PHP to load that extension in php.ini.

You’re better off asking Google for this sort of thing, not here… what you’re getting is not a specific problem with SuiteCRM, it’s your PHP configuration.

1 Like

Hi I have found a solution to SuiteCRM logging out after trying to send mail. It does not fix the error but is an easy work around until a fix implemented and I hope it also works for you. :slight_smile:

Please goto “Profile” > scroll down to “Email Client” and select “External Email Client”

This allows the system to use your system email client.

1 Like

Darrenm, that works for now. Thanks for the solution.