Error sendmail with smtp gmail

Error sendmail with smtp gmail

by Moodle Impleta -
Number of replies: 16

Hi, 


In a moodle installation version 3.3.2 I use the SMTP gmail service to send emails. 

As of September 27, it has not been possible to send email, before this date it has always worked well

I activated the debugsmtp option and the message that is displayed is as follows:

2017-10-06 18:40:16	Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array (
                                      )
2017-10-06 18:40:17 Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
                                      error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [D:\apps\moodle\moodleapp\lib\phpmailer\class.smtp.php line 293]
2017-10-06 18:40:17 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [D:\apps\moodle\moodleapp\lib\phpmailer\class.smtp.php line 293]
2017-10-06 18:40:17 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) [D:\apps\moodle\moodleapp\lib\phpmailer\class.smtp.php line 293]
2017-10-06 18:40:17 SMTP ERROR: Failed to connect to server:  (0)
2017-10-06 18:40:17 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Any idea to solve this problem
Average of ratings: -
In reply to Moodle Impleta

Re: Error sendmail with smtp gmail

by Matt T -
Try changing the protocol from SSL to TLS and change the port from 465 to 587.
In reply to Matt T

Re: Error sendmail with smtp gmail

by Moodle Impleta -

Hi!


When i change to TLS and port 587 the message error is:

2017-10-08 09:39:28	CLIENT -> SERVER: STARTTLS
2017-10-08 09:39:28	SMTP -> get_lines(): $data is ""
2017-10-08 09:39:28	SMTP -> get_lines(): $str is  "220 2.0.0 Ready to start TLS
                   	                  "
2017-10-08 09:39:28	SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-10-08 09:39:29	Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
                   	                  error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [D:\apps\moodle\moodleapps\lib\phpmailer\class.smtp.php line 369]
2017-10-08 09:39:29	SMTP Error: Could not connect to SMTP host.
2017-10-08 09:39:29	CLIENT -> SERVER: QUIT

In reply to Moodle Impleta

Re: Error sendmail with smtp gmail

by Matt T -

Do you have OpenSSL support enabled in PHP?

In Moodle Site Admin, go to Server > PHP Info and see if "OpenSSL" is listed. It should appear like this:

OpenSSL support enabled in phpinfo()

In reply to Matt T

Re: Error sendmail with smtp gmail

by Moodle Impleta -

Hi!


Yes is enable!

ssl


PS: The URL access is not a domains, is a IP public.

In reply to Moodle Impleta

Re: Error sendmail with smtp gmail

by Mike Senders -

Please let us know if have solved the problem yet?

I have the same problem. It just started a couple of weeks ago -it was working fine- and I do not know what the problem is. I have checked almost everything and it seems that there is no problem as far as google account and configurations.

Here what I have as far as Google SMTP connection:

2017-12-17 13:13:05	Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array ()
2017-12-17 13:13:07	SMTP ERROR: Failed to connect to server:  (0)
2017-12-17 13:13:07	SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
On my test site it outputs a similar message pasted below:
2017-12-17 13:13:07	SMTP connect() failed. Connection failed. Error #2:stream_socket_client(): Failed to enable crypto [C:\inetpub\wwwwroot\lib\phpmailer\src\SMTP.php line 324.
I checked the line 324 and it seems Ok and have not changed/modified it. This is on Moodle 3.3
323 STREAM_CLIENT_CONNECT
324 $socket_context
Is that Google has blocked my email stream concerning ssl port 465?
I appreciate if you have any solution for this and let me know. Thanks


In reply to Mike Senders

Re: Error sendmail with smtp gmail

by DJ Trader -

Hi, friend, I am having the same problem, I have the latest version of moodle 3.4 I would like to know if you could solve the problem I have 4 days giving me hard and I can not solve the problem could you help me?

In reply to DJ Trader

Re: Error sendmail with smtp gmail

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello,
you should install https://moodle.org/plugins/local_mailtest and report back here all the SMTP conversation done by the test- you can use ******** to anonymize the sensitive data there - to let us know what is "the problem".

HTH,
Matteo

Average of ratings: Useful (1)
In reply to Matteo Scaramuccia

Re: Error sendmail with smtp gmail

by DJ Trader -

Hi, thanks for answering this is the error that throws me


2018-04-06 16:25:21 Connection: opening to smtp.gmail.com:465, timeout=300, options=array() 2018-04-06 16:25:21 Connection: opened 2018-04-06 16:25:31 SERVER -> CLIENT: 2018-04-06 16:25:31 SMTP NOTICE: EOF caught while checking if connected 2018-04-06 16:25:31 Connection: closed 2018-04-06 16:25:31 SMTP Error: Could not connect to SMTP host. 2018-04-06 16:25:31 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting


I have tried with ssl, with other ports but nothing I can not do the sending of email, neither with gmail nor with my hosting. Do you have any suggestions that you can take into account please?


In reply to DJ Trader

Re: Error sendmail with smtp gmail

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello,
it looks like you're making a mistake when setting the combination of SMTP port (via SMTP hosts in Moodle) and encryption (SMTP security in Moodle) e.g. if you're using GMail you should use 587 and TLS i.e. SMTP Hosts set to smtp.gmail.com:587 and SMTP security set to TLS.

Could you show us the actual settings you're using in Moodle for the outgoing emails (but real username and password, to avoid sharing sensitive data here) as they appear in Site administration > Server > Email > Outgoing mail configuration?

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Error sendmail with smtp gmail

by DJ Trader -

Thanks for your help, I have done what you tell me and this error has come to me





AND THE CONFIGURATION IS THIS:




I have made several tests and anyway and nothing, also activate the function in gmail to access from outside in SMTP.

Thanks for the help you can give me

In reply to DJ Trader

Re: Error sendmail with smtp gmail

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello,
OK we made a step forward: the connection works but the authentication.

You should click for help in the URL written in the SMTP conversation, https://support.google.com/mail/answer/78754: shortly, you need to log into the GMail account via browser with the credential used in the Moodle SMTP configuration and navigate to https://www.google.com/settings/security/lesssecureapps to set Allow less secure apps to ON.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Error sendmail with smtp gmail

by DJ Trader -

Thank you very much Matteo for all your help. (If there is an error, excuse me because I am using google translator, my language is Spanish)

You know that I have decided to place it with the data of my main server, since with gmail I have not been able even with the data and your suggestions. but now I get another error and I really have already despaired I have done many things I have tried muchso ports etc. I'll show you all in detail to see if you can help me friend.


This is the error that gives me with the data of the test mail of my hosting

2018-04-08 02:16:58	Connection: opening to smtp.ceefi.com.es:587, timeout=300, options=array()
2018-04-08 02:16:58	Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: Name or service not known [/home/subcarpeta/midominio.com/lib/phpmailer/src/SMTP.php line 324]
2018-04-08 02:16:58	Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.ceefi.com.es:587 (php_network_getaddresses: getaddrinfo failed: Name or service not known) [/home/subcarpeta/midominio.com/lib/phpmailer/src/SMTP.php line 324]
2018-04-08 02:16:58 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0) 2018-04-08 02:16:58 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

Here is the configuration data of the mail server


error


And these are the data that my hosting gives me to configure my mail


asd

I have read a lot and also seeing the error that appears to be in SMTP.php line 324 but I do not see anything in the out of the ordinary.


I show you my SMTP.php


asdasd


Again, thank you for your response and for all the help you can give me

In reply to DJ Trader

Re: Error sendmail with smtp gmail

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello,
it fails since the "name" smtp.ceefi.com.es doesn't exist: if you'll remove the trailing .es it will work i.e. it will connect and then you'll see if your settings about the authentication will be fine.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: Error sendmail with smtp gmail

by DJ Trader -

Matteo Thank you for really attending, I am very grateful.

You suggest my domain is ceefi.com.es is not .ceefi.com, this is why I do not understand why you follow me to remove the .es, this is part of the content of my domain, check it well that I am no longer using gmail to send emails if not my hosting provider. I really do not understand why you suggest removing me. You could exile me this better.

In reply to DJ Trader

Re: Error sendmail with smtp gmail

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

Because domains do not have two identifiers at the end - a domain would either be .com or .es but not both.

Reading through, I wonder why you switched in the middle.  Matteo had you really close to getting gmail working (did you allow the non secure apps in your account as he suggested?) and now you are starting from scratch again.  It seems that you would be better to finish up the gmail part as you had that connecting, just needed to change a setting.  

In reply to DJ Trader

Re: Error sendmail with smtp gmail

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hello,
internet is made of names which are resolved into IP addresses; otherwise, it won't work.

Your supposed name smtp.ceefi.com.es doesn't exist: you can verify by yourself by using a resolver like http://ping.eu/nslookup/.
If you remove what suggested the DNS resolution will work: guessing that you've not properly configured your DNS or you're supposing something which the Internet doesn't know.

Check with your Hosting Provider what is the domain you've bought and how it is actually configured: you can have a .com Top-Level Domain, a .es TLD but not a .com.es Second-Level Domain (Refs: https://en.wikipedia.org/wiki/List_of_Internet_top-level_domains and https://en.wikipedia.org/wiki/Second-level_domain#Spain).

HTH,
Matteo