-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Comments
I should add... |
Is there anything else that I can do to help get this issue addressed? |
@mruch2 please don't skip parts of the Issue template... knowing your SuiteCRM version, for example, is not a minor detail for this Issue... |
Good point. Version 7.9.4 the latest. |
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. |
Either one seems to have the same problem.
|
@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! |
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. |
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? |
Yes that is what I mean. |
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? |
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 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... |
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).
Please let me know your results. Thanks. |
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: Error Message in Log: (different than the first one I got) Maybe a step closer...? |
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. |
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? |
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:
I obfuscated quite a few things in there, of course. I hope this helps! |
Here is my output.
|
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' |
@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 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 Let us know the results. |
@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? 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:
|
@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. |
@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. |
Here is what I am running exactly.
Now I tried without TLS. I switched to SSL and port 465 and this is the error I got.
|
@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 |
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 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
That will give you a big bunch of information about your configuration, including the exact |
@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? |
@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? |
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.
|
Ok so what is next? |
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. |
Awesome thanks. Hopefully we can get to the bottom of it. For many peoples sake. |
@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...
... 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: 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. |
@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? |
@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.
|
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. |
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. |
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: 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? |
@stancel - it is localhost. |
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. |
Just to confirm the setting I am changing is "host_name" correct? If so that does not appear to have worked. |
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. |
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().
|
@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.
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. |
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. |
@mruch2 if you try wrapping the smtpConnect in a try block, can you catch that exception? In put a 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 ( 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: But in SuiteCRM, there are many |
Another experience from the forums, with a different workaround...
|
I made some progress on this today:
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. |
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). |
I suggest closing this one, unless someone has a different opinion. My logic:
Am I right, or am I missing something? Thanks |
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
The text was updated successfully, but these errors were encountered: