Email Notifications Failing in Cron

Iā€™m having a problem with email notifications after installation. Here is a copy of the log. Can anyone help?

Job 9251a574-0b18-0e0e-280a-59ed740b7024 (Run Email Reminder Notifications) failed in CRON run

Iā€™m running 7.8.8 on Jessie. I have a bunch of diagnostic errors that I need to correct so any help with this one would be great.

Are your other cron jobs running properly?

Is your mail setup working? Can you send test emails from the system account?

You should have more messages in your log, before that one, explaining what went wrong to make the job fail.

I can send test emails, but there is a caveat, I changed the source code to make it work. Iā€™ve been dealing with phpmailer issues since Sugar, and manually changing the transfer protocol to sendmail has always worked for me. For the sake of the community (a lot of people complain about the SMTP errors), Iā€™m going to change the code back the original and start from there. Here is the error log:

Mon Oct 23 14:36:57 2017 [28510][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.
Mon Oct 23 14:36:57 2017 [28510][1][FATAL] SugarPHPMailer encountered an error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mon Oct 23 14:36:57 2017 [31370][-none-][FATAL] Retrieving record by id users:1 found Query Failed: SELECT users.* FROM users WHERE users.id = ā€˜1ā€™ AND users.deleted=0 LIMIT 0,1: MySQL error 2006: MySQL server has gone away

Test emails do not workā€¦

Hi

I have been working on these SMTP bugs this weekend. I found something that might help. The test emails from outbound accounts are getting sent with the ā€œFromā€ and ā€œFromNameā€ field coming from the general (system) outbound account, defined in Admin / Email settings.

If this doesnā€™t match the email in the outbound account youā€™re trying to configure, AND IF your SMTP provider gets annoyed with that, your test email wonā€™t send. Your actual emails might send, later, if you provide the matching ā€œFromā€ and ā€œFromNameā€ (on the Campaign wizard, for example).

Knowing this, you can test if this is your problem, and work around it, until some fix is made.

Letā€™s forget the email campaign bug for now. Since I switched back to the original email.php file my test emails are not working at all.

Tue Oct 24 10:27:18 2017 [34349][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 Oct 24 10:27:18 2017 [34349][1][FATAL] SugarPHPMailer encountered an error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Iā€™m back at the original SMTP configuration error to enable email on 1and1 servers. In Sugar, I turned on the debug mode and looked at the output and discovered I needed to be sending my email via sendmail. Suite is supposed to have corrected that bug but I still canā€™t send an email. Before I even worry about campaign email, I have to have this debugged. Will the email debugger be able to isolate the problem, and if so, where is it located in SuiteCRM?

Well, this is a work in progress but Iā€™m glad I have someone else worried about this.

Make a backup copy of your include/SugarPHPMailer.php

Now open it and swap the smtpConnect function for this one:


    public function smtpConnect($options = array())
    {
   $this->phpMailerFullLog='';
   $phpMailerExceptionMsg='';
   try {
        $saveExceptionsState = $this->exceptions;
        $this->exceptions = true;
        $this->SMTPDebug = 14;

        $connection = parent::smtpConnect();
        $this->exceptions =  $saveExceptionsState;
     } catch (Exception $e) {
        $phpMailerExceptionMsg=$e->getMessage();
        $GLOBALS['log']->fatal("Internal PHPMailer smtpConnect Exception: { $phpMailerExceptionMsg }");
        $GLOBALS['log']->fatal("Internal PHPMailer smtpConnect Full debug log: { $this->phpMailerFullLog }");
   }

        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
        }

        return $connection;
   }

This is still not capturing the full debug log as I want it to, but at least it will give you a detailed internal Exception text which is useful.

Now add this function before it, in the same file:


    public function send() {
        $this->phpMailerFullLog='';
        $GLOBALS['log']->fatal("PHPMailer Send Function override: { FromName: $this->FromName From: $this->From Host: $$
        
        //use these to manually override values, to test if these are the problematic parameters:
        //$this->From = 'myname@mysite.com';
        //$this->FromName = 'My name ';

        $ret = parent::send();
        $GLOBALS['log']->fatal("Internal PHPMailer Send Full debug log: { $this->phpMailerFullLog }");
        return $ret;
     }

Again - the full debug log is not showing, but there will be some useful extra info for you in the logs.

If you want, you can try overriding the parameters to reach acceptable values. This is just a way to test what works, and prove if the problem is really this one or not.

Let me know what you find. Thanks.

I inserted you function and received a PHP warning that initial segment has a syntax error in this line:

$GLOBALS[ā€˜logā€™]->fatal(ā€œInternal PHPMailer Send Full debug log: { $this->phpMailerFullLog }ā€);

Since I had a backup of the original file I ran it anyway. The SMTP error did not appear, but neither did the confirmation email either. I check my inbox and there was nothing there. The resulting PHP error that was displayed is this.

Parse error: syntax error, unexpected ā€˜ā€™ (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /homepages/14/d697451344/htdocs/rtrdigital/crm/include/SugarPHPMailer.php on line 369

This error reads the same as Dreamweaver, as the line mentions above is in fact line 369 of the SugarPHPMailer file. Thoughts?

Sorry, I left out a required declaration. Add this outside the functions, at class level:

  public $phpMailerFullLog=''; 

You can put it before this line, for example:

    public function send() {

The additional declaration of the $$phpMailerFullLog did not fix the error. The syntax error still reads the same.

This is my most current version of the ā€œsmtpConnectā€ function:


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;
   }

And the ā€œsendā€ functions, and the variable declaration:



public $phpMailerFullLog='';

public function send() {
   $GLOBALS['log']->fatal("------------ Entering SugarMailer send");
        $this->phpMailerFullLog='';

//override values here if you want to easily test different arguments:
//$this->From = 'me@there.com';
//$this->Sender = 'me@there.com';
//$this->Password='wrong';
//$this->FromName = 'Me';

        $GLOBALS['log']->fatal("PHPMailer Send Function override: { FromName: $this->FromName From: $this->From Host: $$

        $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;
     }

You should get a nice debug output with that. Be careful, donā€™t post results from that output online without first clearing the BASE64 encoded passwords that might appear in the authentication phase.

I received a preemptive warning about the syntax of this line:

  • $line = strtok($this->phpMailerFullLog, ā€œ\nā€);

Iā€™m going to try to run the script to see if it returns anything, but Dreamweaver typically doesnā€™t miss on these things. Iā€™ll let you know how it went laterā€¦