Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outbound Emails SMTP Connect () #4146

Closed
mruch2 opened this issue Aug 23, 2017 · 71 comments
Closed

Outbound Emails SMTP Connect () #4146

mruch2 opened this issue Aug 23, 2017 · 71 comments
Labels
Priority:Critical Issues & PRs that are critical; broken core functionality, fatal errors - there are no workarounds Status:Fix Proposed A issue that has a PR related to it that provides a possible resolution Type: Bug Bugs within the core SuiteCRM codebase

Comments

@mruch2
Copy link

mruch2 commented Aug 23, 2017

Issue

Cannot send outbound emails.

Expected Behavior

The outbound emails should be working.

Actual Behavior

I used to use a web hosting company for my email. I recently switched to gmail and now have SSL/TLS auth. But it is not working.

Steps to Reproduce

Sending any email from anywhere gives an error message.
This includes sending out emails from the admin section in setting up outbound emails with trying to test. As well as just saving the settings there assuming they are correct and trying to send an email from the quote section by selecting "Email Quotation"

Version Info

SuiteCRM 7.9.4

Error Message:
Wed Aug 23 04:47:31 2017 [5628][5a6f3c04-6cdc-72e2-d455-58ca04892a20][FATAL] SugarPHPMailer encountered an error: The outbound mail server selected for the mail account you are using is invalid. Check the settings or select a different mail server for the mail account.
Wed Aug 23 04:47:31 2017 [5628][5a6f3c04-6cdc-72e2-d455-58ca04892a20][FATAL] SugarPHPMailer encountered an error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

image

@mruch2
Copy link
Author

mruch2 commented Aug 23, 2017

I should add...
Yes I have 2 step verification on.
Yes I have created a app password for crm
Yes I have changed the security setting for less secure apps to connect.

@mruch2
Copy link
Author

mruch2 commented Aug 26, 2017

Is there anything else that I can do to help get this issue addressed?

@pgorod
Copy link
Contributor

pgorod commented Aug 27, 2017

@mruch2 please don't skip parts of the Issue template... knowing your SuiteCRM version, for example, is not a minor detail for this Issue...

@mruch2
Copy link
Author

mruch2 commented Aug 27, 2017

Good point. Version 7.9.4 the latest.

@stancel
Copy link

stancel commented Aug 28, 2017

Hi @mruch2, I believe I know the issue. Are having problems just sending the test email on this outbound email account? From your screenshot I am going to assume that you are creating outbound email account that is in addition to the 'system' outbound email account. Please confirm whether or not that is the case. If this is an additional outbound account then yes, this is a bug. I was just debugging through this over the weekend and noticed that the code to test the outbound email will pair up the email address you put into this screen with the password for the default/'system' outbound email account, thus always giving me that same error. Please confirm either way. Thanks.

@mruch2
Copy link
Author

mruch2 commented Aug 29, 2017 via email

@pgorod
Copy link
Contributor

pgorod commented Aug 29, 2017

@stancel can you please make a nice list of precise "steps to reproduce" the bug? Your description seems the most specific I've seen on this Issue that has been very hard to debug. Thanks!

@mruch2
Copy link
Author

mruch2 commented Aug 30, 2017

Using the Admin section I click on email settings. From there you can plugin all the details you need for your email for SMTP. Then hit send test email and i get the error.

@mruch2
Copy link
Author

mruch2 commented Aug 30, 2017

I called google support and we have tried everything. This seems like a bug and I really need it fixed. How can we get to the bottom of this faster? Since I seem to be the only person having this issue, can I just update all me SuiteCRM files under the directory with the latest ones? Will I lose anything? Will I gain anything?

@pgorod
Copy link
Contributor

pgorod commented Aug 30, 2017

@mruch2 I don't think you're the only one with this issue. Have you seen #3709 and #2807 ? I'm not sure they're the same, but there certainly is something fishy going on.

What do you mean "update your SuiteCRM files"? You mean applying the hotfix branch over your 7.9.4 install?

@mruch2
Copy link
Author

mruch2 commented Aug 30, 2017

Yes that is what I mean.

@mruch2
Copy link
Author

mruch2 commented Aug 30, 2017

Ok so looked at issue 1123 and that sounds like my issue all over again. I tried the TLS setting but that does not work. Nothing else in there seemed viable. Does anyone have a fix for this?

@pgorod
Copy link
Contributor

pgorod commented Aug 30, 2017

I have seen many cases of this problem. currently I'm not sure which fixes are already a part of 7.9.4, and which ones are still on hotfix waiting to be merged to master.

One thing you can try checking is whether the password is saved and retrieved correctly. There was a bug causing this to fail. Have you spotted the place in the code just before the email gets sent? I had that figured out once but I can't look it up right now...

@stancel
Copy link

stancel commented Aug 30, 2017

Hi @mruch2. Please follow these steps and let me know the results. For this test we will only be dealing with the 'system' outbound email account. We'll help you solve the other one in another issue if needed (as it requires a code fix - @pgorod - I will try to get you those details once I get home this evening).

  1. Login as the Google User that you are using to send outbound emails.

  2. Navigate to this address - https://myaccount.google.com/lesssecureapps (look in the top right hand corner of the page while on that screen to make sure it is showing the correct Gmail / GSuite user. If it is not then click on the icon of that user and switch to the same user you'll be using in SuiteCRM to send outbound emails).

  3. Make sure that Allow Less Secure Apps is turned on
    screenshot 2017-08-30 13 16 03

  4. Navigate to your SuiteCRM URL and login as the admin user

  5. Once logged in go to Admin screen --> Email section --> Outbound Email. This should take you to the listings page of the Outbound Email Accounts. (Let me know how many you have listed here in your testing results.)

  6. For this test we are only concerned with the "system" email account. That is the default account SuiteCRM will look for when sending out mail from various places in the system (see getSystemMailerSettings() method in the code)
    outbound_system_email_account

  7. Click into the record for the "system" mailer as seen above and you will be taken to the detail page. Please see screenshot below and verify all details. When you are inputting your Gmail / GSuite username and password please make sure to type them in, instead of copying and pasting them in. The reason for this is to make sure you are not pasting in hidden characters that will prevent the system from properly connecting.
    outbound_system_mailer1

  8. Then click the "Send Test Email" button and a modal window will appear. Put in your personal email address and click "Send"

  9. You should now get a message like seen in the screenshot below along with an email to your personal email. If you get an error here please double check the steps one more time and then let me know the error. This should work for you on the "system" account but not any other outbound email account (due to the bug in the code).
    outbound_system_mailer2

Please let me know your results. Thanks.

@mruch2
Copy link
Author

mruch2 commented Aug 31, 2017

For my gmail account my less secure apps settings are controlled at the domain level. This was configured when I was working on the issue the first time with a google support tech.

From there I followed your step by step information but still have not gotten the same result as it does not state that there has been an email sent. Here is what I get.

Error Message On Screen:

image

Error Message in Log: (different than the first one I got)
Thu Aug 31 02:05:15 2017 [24100][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 Aug 31 02:05:15 2017 [24100][1][FATAL] SugarPHPMailer encountered an error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Maybe a step closer...?

@pgorod
Copy link
Contributor

pgorod commented Aug 31, 2017

I don't have time to go through it now, but I believe the other Issues I linked above contained ways to increase the level of error reporting on that SMTP error. That is essential to work this with this bug.

@mruch2
Copy link
Author

mruch2 commented Aug 31, 2017

I have set it to debug mode but that has not given me a more granular error message. I changed the setting in the SugarPHPMailer and the class.phpmailer and neither changed anything. I even tried repair rebuild and still no better error message.

Also tried setting the auto TLS to false, didnt think in my case this would matter as I want to use TLS. Tried setting the port to 465 and connection type to SSL to see maybe if that worked and nothing. Same error message.

I seen this mentioned (add extension=openssl.so to php.ini) not sure what this entails but do i need to configure openssl?

Anything else I should try?

@pgorod
Copy link
Contributor

pgorod commented Aug 31, 2017

Try this PHP script in the source of your SuiteCRM installation:

<?php
require_once 'include/phpmailer/class.phpmailer.php';
require_once 'include/phpmailer/class.smtp.php';

$mail = new PHPMailer;

$mail->SMTPDebug=14;
$mail->Debugoutput='html';
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';//   // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'source.name@gmail.com';                  // SMTP username
$mail->Password = 'put-the-password-here';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
$mail->Port = 587;
$mail->From = 'source.name@gmail.com'; 
$mail->FromName = 'Gmail Person Name';
$mail->addAddress('some.name@zits.com', 'Some Name');     // Add a recipient
$mail->addReplyTo('source.name@gmail.com', 'Gmail Person Name');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>

On my system this works with the following output:



Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
Connection: opened
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP h88sm5875199wrh.19 - gsmtp"
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP h88sm5875199wrh.19 - gsmtp
CLIENT -> SERVER: EHLO 10.0.0.200
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [94.62.97.218]"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]"
SMTP -> get_lines(): $str is "250-SIZE 35882577"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577"
SMTP -> get_lines(): $str is "250-8BITMIME"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME"
SMTP -> get_lines(): $str is "250-STARTTLS"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-STARTTLS"
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES"
SMTP -> get_lines(): $str is "250-PIPELINING"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING"
SMTP -> get_lines(): $str is "250-CHUNKING"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING"
SMTP -> get_lines(): $str is "250 SMTPUTF8"
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS"
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
CLIENT -> SERVER: EHLO 10.0.0.200
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [94.62.97.218]"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]"
SMTP -> get_lines(): $str is "250-SIZE 35882577"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577"
SMTP -> get_lines(): $str is "250-8BITMIME"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME"
SMTP -> get_lines(): $str is "250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH"
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES"
SMTP -> get_lines(): $str is "250-PIPELINING"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING"
SMTP -> get_lines(): $str is "250-CHUNKING"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING"
SMTP -> get_lines(): $str is "250 SMTPUTF8"
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [94.62.97.218]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
Auth method requested: UNKNOWN
Auth methods available on the server: LOGIN,PLAIN,XOAUTH2,PLAIN-CLIENTTOKEN,OAUTHBEARER,XOAUTH
Auth method selected: LOGIN
CLIENT -> SERVER: AUTH LOGIN
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "334 VXNlcm5hbWU6"
SERVER -> CLIENT: 334 VXNlcm5hnWU6
CLIENT -> SERVER: cdfDSfDffsdFdsffsfsdfsdffsFSf==
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "334 UGthc3dvcmQ6"
SERVER -> CLIENT: 334 UGthc3dvcmQ6
CLIENT -> SERVER: PEFFDFDSFdskFJSDFJDSFDSJFJSDFJSJDSF
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "235 2.7.0 Accepted"
SERVER -> CLIENT: 235 2.7.0 Accepted
CLIENT -> SERVER: MAIL FROM:<source.name@gmail.com>
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "250 2.1.0 OK h88bn5875199wrh.19 - gsmtp"
SERVER -> CLIENT: 250 2.1.0 OK h88bn5875199wrh.19 - gsmtp
CLIENT -> SERVER: RCPT TO:<some.name@zits.com>
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "250 2.1.5 OK h88sm5875199wrh.19 - gsmtp"
SERVER -> CLIENT: 250 2.1.5 OK h88sm5875199wrh.19 - gsmtp
CLIENT -> SERVER: DATA
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "354 Go ahead h88sm5875199wrh.19 - gsmtp"
SERVER -> CLIENT: 354 Go ahead h88sm5875199wrh.19 - gsmtp
CLIENT -> SERVER: Date: Thu, 31 Aug 2017 14:58:48 +0100
CLIENT -> SERVER: To: "Some Name" <some.name@zits.com>
CLIENT -> SERVER: From: "Gmail Person Name" <source.name@gmail.com>
CLIENT -> SERVER: Reply-To: "Gmail Person Name" <source.name@gmail.com>
CLIENT -> SERVER: Subject: Here is the subject
CLIENT -> SERVER: Message-ID: <c48ade8f741c19eca11ab3b63de86c37@10.0.0.200>
CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.21 (https://github.com/PHPMailer/PHPMailer)
CLIENT -> SERVER: MIME-Version: 1.0
CLIENT -> SERVER: Content-Type: multipart/alternative;
CLIENT -> SERVER: boundary="b1_c48ade8f741c19eca11ab3b63de86c37"
CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
CLIENT -> SERVER:
CLIENT -> SERVER: This is a multi-part message in MIME format.
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_c48ade8f741c19eca11ab3b63de86c37
CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
CLIENT -> SERVER:
CLIENT -> SERVER: This is the body in plain text for non-HTML mail
CLIENT -> SERVER: clients
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_c48ade8f741c19eca11ab3b63de86c37
CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
CLIENT -> SERVER:
CLIENT -> SERVER: This is the HTML message body <b>in bold!</b>
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER:
CLIENT -> SERVER: --b1_c48ade8f741c19eca11ab3b63de86c37--
CLIENT -> SERVER:
CLIENT -> SERVER: .
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "250 2.0.0 OK 1504187931 h88sm5875199wrh.19 - gsmtp"
SERVER -> CLIENT: 250 2.0.0 OK 1504187931 h88sm5875199wrh.19 - gsmtp
CLIENT -> SERVER: QUIT
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "221 2.0.0 closing connection h88sm5875199wrh.19 - gsmtp"
SERVER -> CLIENT: 221 2.0.0 closing connection h88sm5875199wrh.19 - gsmtp
Connection: closed
Message has been sent 

I obfuscated quite a few things in there, of course.

I hope this helps!

@mruch2
Copy link
Author

mruch2 commented Sep 1, 2017

Here is my output.

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\xampp\php\ext\openssl.so' - The specified module could not be found.
 in Unknown on line 0
Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()<br>
Connection: opened<br>
SMTP -&gt; get_lines(): $data is &quot;&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;220 smtp.gmail.com ESMTP j7sm1019888pfb.30 - gsmtp&quot;<br>
SERVER -&gt; CLIENT: 220 smtp.gmail.com ESMTP j7sm1019888pfb.30 - gsmtp<br>
CLIENT -&gt; SERVER: EHLO MIKE-DESKTOP<br>
SMTP -&gt; get_lines(): $data is &quot;&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;250-smtp.gmail.com at your service, [47.146.134.237]&quot;<br>
SMTP -&gt; get_lines(): $data is &quot;250-smtp.gmail.com at your service, [47.146.134.237]&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;250-SIZE 35882577&quot;<br>
SMTP -&gt; get_lines(): $data is &quot;250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;250-8BITMIME&quot;<br>
SMTP -&gt; get_lines(): $data is &quot;250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;250-STARTTLS&quot;<br>
SMTP -&gt; get_lines(): $data is &quot;250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME250-STARTTLS&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;250-ENHANCEDSTATUSCODES&quot;<br>
SMTP -&gt; get_lines(): $data is &quot;250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;250-PIPELINING&quot;<br>
SMTP -&gt; get_lines(): $data is &quot;250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;250 SMTPUTF8&quot;<br>
SERVER -&gt; CLIENT: 250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8<br>
CLIENT -&gt; SERVER: STARTTLS<br>
SMTP -&gt; get_lines(): $data is &quot;&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;220 2.0.0 Ready to start TLS&quot;<br>
SERVER -&gt; CLIENT: 220 2.0.0 Ready to start TLS<br>
SMTP Error: Could not connect to SMTP host.<br>
CLIENT -&gt; SERVER: QUIT<br>
SMTP -&gt; get_lines(): $data is &quot;&quot;<br>
SMTP -&gt; get_lines(): $str is  &quot;&quot;<br>
SERVER -&gt; CLIENT: <br>
SMTP ERROR: QUIT command failed: <br>
Connection: closed<br>
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting<br>
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

@mruch2
Copy link
Author

mruch2 commented Sep 1, 2017

In researching a bit I don't actually see this PHP library that it states it is missing in any of the latest download of PHP I pulled. There is a PHP_Openssl.dll in the folder but no ".so"

'C:\xampp\php\ext\openssl.so'

@stancel
Copy link

stancel commented Sep 1, 2017

@mruch2 - if you are on Windows the file extension will be .dll (dynamically linked library) instead of .so (shared object) on Linux. In your Apache and CLI php.ini file(s) you should enable extension=php_openssl.dll
instead of
extension=php_openssl.so

You will need to restart your web server (XAMPP in your case) after making this change in all applicable php.ini files.

Do you have the ability to debug and set a breakpoint? If so, please put on at the following file and line number.

<Project_Root>/include/phpmailer/class.phpmailer.php
Line 1683 (for version 7.9.4)
Should look like this: if ($this->SMTPAuth)

Let us know the results.

@mruch2
Copy link
Author

mruch2 commented Sep 1, 2017

@stancel - The only difference I got was the first portion of the error message is gone. Outside of that I did not get much further. The breakpoint seems to be ignored as I don't even get step into options. Its like it is not running the code period.

When you said all applicable php.ini files what did you mean?
c:\xampp\php\php.ini
c:\xampp\htdocs\suitecrm\php.ini

Now when I launch Apache and open the ini from there I believe it is the first one listed above. It also points to an extension directy of c:\xampp\php\ext

Here is the debug output:

Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
Connection: opened
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP r87sm1402423pfd.19 - gsmtp"
SERVER -> CLIENT: 220 smtp.gmail.com ESMTP r87sm1402423pfd.19 - gsmtp
CLIENT -> SERVER: EHLO MIKE-DESKTOP
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [47.146.134.237]"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [47.146.134.237]"
SMTP -> get_lines(): $str is "250-SIZE 35882577"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577"
SMTP -> get_lines(): $str is "250-8BITMIME"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME"
SMTP -> get_lines(): $str is "250-STARTTLS"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME250-STARTTLS"
SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES"
SMTP -> get_lines(): $str is "250-PIPELINING"
SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING"
SMTP -> get_lines(): $str is "250 SMTPUTF8"
SERVER -> CLIENT: 250-smtp.gmail.com at your service, [47.146.134.237]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
CLIENT -> SERVER: STARTTLS
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS"
SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
CLIENT -> SERVER: QUIT
SMTP -> get_lines(): $data is ""
SMTP -> get_lines(): $str is ""
SERVER -> CLIENT: 
SMTP ERROR: QUIT command failed: 
Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

@pgorod
Copy link
Contributor

pgorod commented Sep 1, 2017

@mruch2 if you can edit your posts to put the debug outputs inside "code" tags, that would be nice.

Here on GitHub you do that by adding a triple backtick in the beginning and another one in the end.

@pgorod
Copy link
Contributor

pgorod commented Sep 1, 2017

@mruch2 by looking at your debug outputs, and comparing to mine, it doesn't seem like you're trying to authenticate with Gmail SMTP at all. Can you turn on authentication somehow?

If you post more debug outputs here, make sure you garble any password hashes before posting.

@mruch2
Copy link
Author

mruch2 commented Sep 1, 2017

Here is what I am running exactly.

<?php

require_once 'include/phpmailer/class.phpmailer.php';
require_once 'include/phpmailer/class.smtp.php';

$mail = new PHPMailer;

$mail->SMTPDebug=14;
$mail->Debugoutput='html';
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';//   // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'email address 1';                  // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable encryption, 'ssl' also accepted
$mail->Port = 587;
$mail->From = 'email address 1'; 
$mail->FromName = 'my company name';
$mail->addAddress('email address 2', 'my name');     // Add a recipient
$mail->addReplyTo('email address 1', 'my company name');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

?>

Now I tried without TLS. I switched to SSL and port 465 and this is the error I got.

Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed
Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): Failed to enable crypto
Connection: Failed to connect to server. Error number 2. "Error notice: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error)
SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

@mruch2
Copy link
Author

mruch2 commented Sep 1, 2017

@pgorod - Now since I copied your code exactly what could cause there to be no authentication? I am running it in the main folder of SuiteCRM. Path c:\xampp\htdocs\SuiteCRM

@pgorod
Copy link
Contributor

pgorod commented Sep 1, 2017

I'm afraid I don't know. I would like to compare the outputs of our two debug runs (mine and yours, with the exact same settings), but yours is getting annoying HTML codes (like &quot;) that are not helping... can you get us a clean copy-paste from your browser window?

Also, to advance on your efforts with the php.ini configuration, you can add this line near the end of your script, just before the final ?>

phpinfo();

That will give you a big bunch of information about your configuration, including the exact php.ini paths, and the actually loaded modules.

@stancel
Copy link

stancel commented Sep 1, 2017

@mruch2 - for the breakpoint I asked you about adding and debugging through - Can you please look at the value of the username and password variables there and confirm that they match the Gmail/GSuite account that you are trying to connect to? If they are can you please let us know the message value inside the exception?

@pgorod
Copy link
Contributor

pgorod commented Sep 1, 2017

@stancel I see that is a useful debugging approach if the simple script was able to connect to SMTP. Then we could check for SuiteCRM bugs (namely the infamous missing password).

But if the script can't send (using the same PHP environment, and the same mailer class, and the same details as mine), then that seems to indicate a previous configuration problem, don't you agree?

@mruch2
Copy link
Author

mruch2 commented Sep 1, 2017

Ok I did some researching because I noticed that my debugger VS Code was not picking up any breakpoints even in the initial file. So what I did was research how to configure it. I have that setup now. I have an error that I think may lead us down a path that we need to go.

On line 367 of class.smtp.php I get this error.

Exception has occurred.
Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

@mruch2
Copy link
Author

mruch2 commented Sep 2, 2017

Ok so what is next?

@stancel
Copy link

stancel commented Sep 2, 2017

Hang tight. I have debugged through the issue and can now reproduce it in my local environment (Mac / MAMP / PHP 7.0.15), but it does not happen on my server (Ubuntu 16.04.3 / Apache / PHP 7.0.22).

I have debugged, see two issues happening and have just overcome them in my local to send a successful email. That involved changing the SMTP password variable in memory though. This was the same issue I mentioned previously, but did not have time to fix before. Just double checking some things, be back with you later today with info to try for a fix, or a pull request.

@mruch2
Copy link
Author

mruch2 commented Sep 2, 2017

Awesome thanks. Hopefully we can get to the bottom of it. For many peoples sake.

@pgorod
Copy link
Contributor

pgorod commented Sep 2, 2017

@stancel there are already a few open issues regarding the bugs with saving email passwords. For that aspect of the problem, make sure you explore those issues too: #4057, #3841, and there may be others.

About this one here, the SMTPConnect fail, if we solve it by adding flags called like this...

        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true

... then I think we should investigate exactly these issues, especially the self-signed thing. Does anybody know how the openssl PHP extension handles certificates, where it gets them from? Maybe @mruch2 is running his computer with a self-signed certificate in there?

The phpmailer Troubleshooting Docs have a section on this:
https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#php-56-certificate-verification-failure

and basically their advice is to correct the SSL configuration. That's probably the way forward for @mruch2. But for the SuiteCRM project I'm also trying to make this error more apparent and better reported.

@mruch2
Copy link
Author

mruch2 commented Sep 2, 2017

@pgorod - wouldnt it use googles certificate as I am sending it through their mailing service? By the way the settings that you have listed there dont exactly work as SuiteCRM does not acknowledge that the email is sent. When sending an email through the quoting module it goes into a forever loading mode even though it sends. It only sends now because I put in that section of code in the phpmailer file.

For whatever reason this does not completely work for SuiteCRM although your script can use it just fine.

Another thing I think you are on to something about the SSL config. Where are the settings for that?

@mruch2
Copy link
Author

mruch2 commented Sep 2, 2017

@pgorod - Here is something interesting. Changing some settings to isolate the issue and I noticed that only one option in the array actually matters. I modified the code and got the same result. Here is the passed parameter.

public $SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            //'verify_peer_name' => false//,
            //'allow_self_signed' => false
        )
    );

@pgorod
Copy link
Contributor

pgorod commented Sep 2, 2017

There's a certificate on each side, Google identifies itself with one, you identify yourself with another. I really don't know much about certificates, and much less about PHP openssl module certificates. You'll have to Google for it, but at least now you know exactly what to search for: that error message, and that verify_peer option.

I can tell you I never did any certificates configuration to get my emails to send - you might be able to work through this just by playing with your PHP configs.

The other email errors are other email errors. SuiteCRM just underwent a complete rewrite of its Email module, there were many difficulties in this project, it's still a bit wobbly. But my advice is to treat each Issue as a separate Issue: investigate it separately, and report it separately if necessary.

@mruch2
Copy link
Author

mruch2 commented Sep 2, 2017

Ok I just went to startssl.com and got a free cert. I installed it through the windows installer tool. Now I am going to try and see if I get a different result. Not sure yet.

@stancel
Copy link

stancel commented Sep 2, 2017

Hey guys, so here is where things stand at the moment.

When I first reopened my local debugging environment I was able to recreate the issue and saw that the problem was failing in the startTLS() method inside the PHPMailer library. The logic of the method looks fine, but to test further I modified PHPMailer library file class.smtp.php::startTLS() by adding this backstop onto line 363:
$crypto_method |= STREAM_CRYPTO_METHOD_ANY_CLIENT
The idea behind this was to give the socket the ability to fall back to SSL encryption on the socket - basically still connect using any SSL/TLS method possible (I know this is not the secure long term fix - just getting through the issue at this point). That worked for me but my connection still failed in the PHPMailer library file class.phpmailer.php line 1684:
if (!$this->smtp->authenticate
That failed because I had taken a backup of my Prod DB from the server and restored it onto my local testing environment. Apparently when the outbound passwords are saved they are hashed or salted using some local variable so the base64 encoded value stored in the DB outbound_email.mail_smtppass did not decode to the correct password thus properly causing it to fail there when the wrong password was sent. Re-saving the correct password into the Outbound Email account UI and clicking save updated the hashed (and probably salted) base64 encoded value in outbound_email.mail_smtppass thus enabling me to connect the next time.

Now on to the nitty gritty. Shortly after the initial debug everything was working for me continuously. I was trying to get it to once again fail there like it has for @mruch2. I was finally able to do so by changing the hostname in my config.php. Mine was still set to our production server's value that has a valid wildcard cert signed by a recognized CA. When changing that value to "localhost/SuiteCRM" the SMTP fails there every time like it does for @mruch2.

@mruch2, what is the value of "hostname" in your config.php file?

@mruch2
Copy link
Author

mruch2 commented Sep 2, 2017

@stancel - it is localhost.

@stancel
Copy link

stancel commented Sep 2, 2017

Do me a favor and temporarily change it to crm.processfast.com and then test again. That is my prod server that has a valid cert setup. Please let me know the results from that test. I believe that Google is trying to test for a valid cert from the calling server and if that fails they send back a failing command to the HELO call being made from SuiteCRM --> PHPMailer --> Gmail/GSuite's server.

@mruch2
Copy link
Author

mruch2 commented Sep 2, 2017

Just to confirm the setting I am changing is "host_name" correct? If so that does not appear to have worked.

@stancel
Copy link

stancel commented Sep 2, 2017

Yes, you need to change "host_name" in config.php to the value I gave you. Now, try one more thing. Please fully shut down your WAMPP instance, clear your browser's cache and close it. Then reopen the browser, start your WAMPP instance back up, login to your local SuiteCRM instance, try the same steps again. However, if the first test fails I ask you to stay on that page and click the "Send Test Email" button again without refreshing the page. Please let me know if it sends then.

@stancel
Copy link

stancel commented Sep 3, 2017

FYI - the reason I am asking for you to perform the test this way is to see if the resource ($this->smtp_conn) is being released or not set properly on the first connection with correct parameters, then on the second request that resource is valid and then working. I have seen a few debugging tests in my local that would lead me to believe that this is the case.

@pgorod - Yes, just changing the SMTP options array to pass the parameter of verify_peer = false, would seem to work, but I think there is more going on than that. If you just want to test that then all you or @mruch2 need to do is put the below lines into the first lines of the SugarPHPMailer::smtpConnect().

$options = ['verify_peer' => false];
$connection = parent::smtpConnect($options);

@mruch2
Copy link
Author

mruch2 commented Sep 3, 2017

@stancel - Ok I tried both mentioned next steps. I traded out my host_name flushed browser cache restarted apache. No change. (I did remove the added code that I previously put in the PHPMailer)

I also attempted to simply add the two lines of code mentioned for the $options, recognizing I actually have to modify a line of code that is in this function as $connection = exists, inside the SugarPHPMailer and removing the code that I put into the PHPMailer file itself. This did not net the same result as having the code inside the PHPMailer file.

Edit: Looking at your code further it did not actually match the parameters that we have been passing so I modified the $options statement a little bit. Now it is the same result.

$options = array(
                'ssl' => array(
                    'verify_peer' => false
                )
            );

Edit 2: Ok I have everything working without any internal errors. I changed my host name to my crm site. Then I un-commented the options code inside the SugarPHPMailer.php that you said to place in there and everything appears to work correctly inside sure now. Still need to figure out why we need to pass that option.

@stancel
Copy link

stancel commented Sep 3, 2017

Glad to hear that worked and you are up and running now. I believe you are having to pass that option because client cert validation is being performed by default by either the OpenSSL library or on Google's side from their servers, which is one of the reasons why I was asking you to change around the host name in your config. Passing that would essentially just disable that check. If you want to check this further, I would start by looking at your OpenSSL config file, the chosen options inside of it and any directories it references for self signed certs or CA's (certificate authorities). Per your previous post, you should like into this file:

c:/usr/local/ssl/openssl.cnf

I'll have to bow out for researching this one further as I've got some blocking issues for my own business that I need to solve as well. I'll try to put in a pull request for this issue later today though in case the maintainers decide they would like to merge this in.

If you ( @mruch2 ) or @pgorod would be kind enough to test my pull request #4168 to fix and enhance issue #4111 if you get some free time, I would appreciate it.

stancel added a commit to ProcessFast/SuiteCRM that referenced this issue Sep 3, 2017
@pgorod
Copy link
Contributor

pgorod commented Sep 4, 2017

@mruch2 if you try wrapping the smtpConnect in a try block, can you catch that exception?

In include/SugarPHPMailer.php, around line 362

put a try { just at the start, and some block to catch it at the end.

The function would look like this in the end:

    public function smtpConnect($options = array())
    {
    try {
        $connection = parent::smtpConnect();
        if (!$connection) {
            global $app_strings;
            if (isset($this->oe) && $this->oe->type === 'system') {
                $this->setError($app_strings['LBL_EMAIL_INVALID_SYSTEM_OUTBOUND']);
            } else {
                $this->setError($app_strings['LBL_EMAIL_INVALID_PERSONAL_OUTBOUND']);
            } // else
        }
        return $connection;
     } catch (phpmailerException $e) {
          echo '---------------------------------------------------';
          echo $e->errorMessage(); 
          echo '---------------------------------------------------';
     } catch (Exception $e) {
          echo $e->getMessage(); //error messages from anything else
    }
    } // fn

I'd like to know if we can get that detailed message (Exception has occurred. Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed) from here.

But it seems that for this to work, we'd have to change the statement instantiating PHPMailer to pass true to the constructor. On my script, this looks like this:
$mail = new PHPMailer(true);

But in SuiteCRM, there are many new PHPMailer statements, and I'm not sure which one applies for this... :-( I'm afraid I don't have time to investigate right now...

@Dillon-Brown
Copy link
Contributor

Dillon-Brown commented Sep 7, 2017

@mruch2 @stancel @pgorod Hi guys, brilliant job debugging this. I'll label this as a high priority bug for now and we will discuss the implications of this and stancel's proposed fix as soon as possible. Thanks for all the help!

@Dillon-Brown Dillon-Brown added Type: Bug Bugs within the core SuiteCRM codebase Status:Fix Proposed A issue that has a PR related to it that provides a possible resolution Priority:Critical Issues & PRs that are critical; broken core functionality, fatal errors - there are no workarounds labels Sep 7, 2017
@pgorod
Copy link
Contributor

pgorod commented Oct 10, 2017

Another experience from the forums, with a different workaround...

Hi all
I installed version 7.9.6 and had the error:
SMTP connect() failed. github.com/PHPMailer/PHPMailer/wiki/Troubleshooting.
I tried several workarounds I found in the forum, like changing files in the include-folder, hardcoding my server settings, trying all combinations in the UI (with port 465, 587, 25 and with SSL, TLS, None) etc etc.
None of these fixed my error.
Now, I finally found a solution, posting it to enable other users to try this fix, if they are fighting with the outgoing email settings:
--> Use n email password which is just made up of a-z, A-Z, 0-9. So, DONT use special characters like +=(),. and so on
I had a complex password with special chars. Changing this fixed it for me :-)

Hope it helps someone, too

@pgorod
Copy link
Contributor

pgorod commented Oct 22, 2017

I made some progress on this today:

  • I can get the full exception text from smtpConnect and put it in the log: this is really helpful to make the error much more focused and avoids needless mystery. I'll make a PR when I'm finished with all this.
  • I found yet another very misleading case, which surely is tripping a lot of people: the Send test email from the Outbound Accounts configuration uses the From and FromName from the outbound system account. If that is different from the Account you're actually configuring at the moment, that is enough for many SMTP providers to give you a "not authenticated" reply, which sounds like a bad password problem, but actually isn't. Interestingly, in this case, it's the Test email that doesn't work, but then the actual email or campaign might work, because there you are asked for a From address, and if you put in the correct one, the email will send...

All this I tested on a 7.8.7, I expect the same problems apply to 7.9.x, but I'll have to try it someday.

@pgorod
Copy link
Contributor

pgorod commented Nov 3, 2017

I moved this last case I found to a new Issue #4479.

This Issue here has enough entity by itself (with that verify_peer option).

@pgorod
Copy link
Contributor

pgorod commented Mar 13, 2018

I suggest closing this one, unless someone has a different opinion.

My logic:

  • we already have full smtp logging visible from the UI, so this error will be much more apparent to the person configuring email
  • the real fix is proper SSL configuration
  • the workaround is insecure (turn off verify_peer), so we shouldn't add it in our code anyway - let people do it manually if they think it's appropriate

Am I right, or am I missing something? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority:Critical Issues & PRs that are critical; broken core functionality, fatal errors - there are no workarounds Status:Fix Proposed A issue that has a PR related to it that provides a possible resolution Type: Bug Bugs within the core SuiteCRM codebase
Projects
None yet
Development

No branches or pull requests

4 participants