Open fahimmahmoodmir opened 7 years ago
Could you try smtp.gmail.com:587 with TLS ? I think SSL was replaced by TLS on Gmail.
Are you behind a corporate proxy ?
Tried with that as well with following settings:
play.mailer {
host="smtp.gmail.com"
port=587
ssl=no
tls=yes
user="************************@gmail.com"
password="*****************"
debug=yes
}
and still getting exceptions:
play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[CompletionException: org.apache.commons.mail.EmailException: Sending the email to the following server failed :
smtp.gmail.com:587]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:293)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:220)
at play.api.GlobalSettings$class.onError(GlobalSettings.scala:160)
at play.api.DefaultGlobal$.onError(GlobalSettings.scala:188)
at play.api.http.GlobalSettingsHttpErrorHandler.onServerError(HttpErrorHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
Caused by: java.util.concurrent.CompletionException: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:292)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:308)
at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:593)
at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:21)
at scala.concurrent.java8.FuturesConvertersImpl$CF.apply(FutureConvertersImpl.scala:18)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
at scala.concurrent.BatchingExecutor$Batch$$anonfun$run$1.processBatch$1(BatchingExecutor.scala:63)
Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.gmail.com:587
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1421)
at org.apache.commons.mail.Email.send(Email.java:1448)
at play.api.libs.mailer.SMTPMailer$$anon$2.send(MailerPlugin.scala:100)
at play.api.libs.mailer.CommonsMailer.send(MailerPlugin.scala:130)
at play.api.libs.mailer.SMTPMailer.send(MailerPlugin.scala:110)
at play.api.libs.mailer.SMTPDynamicMailer.send(MailerPlugin.scala:117)
at play.api.libs.mailer.MailerClient$class.send(MailerPlugin.scala:56)
at play.api.libs.mailer.SMTPDynamicMailer.send(MailerPlugin.scala:114)
at services.MailerService.sendEmail(MailerService.java:29)
at controllers.ApiController.createUser(ApiController.java:104)
Caused by: javax.mail.MessagingException: Could not convert socket to TLS
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1999)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:709)
at javax.mail.Service.connect(Service.java:386)
at javax.mail.Service.connect(Service.java:245)
at javax.mail.Service.connect(Service.java:194)
at javax.mail.Transport.send0(Transport.java:253)
at javax.mail.Transport.send(Transport.java:124)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1411)
at org.apache.commons.mail.Email.send(Email.java:1448)
at play.api.libs.mailer.SMTPMailer$$anon$2.send(MailerPlugin.scala:100)
Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unab
le to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path t
o requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)
Nope no proxy at all.
Are you using -Djavax.net.ssl.trustStore
in your JVM arguments ? I think your truststore does not contains certification authorities.
Are you using a custom Java installation ? By default the JRE trusts all certificates that somehow link to one of the certificates in jre/lib/security/cacerts, unless you have configured a different truststore.
nah i am using the default JRE that i downloaded from the official site. So i didn't even customize any kind of arguments for JVM. Neither i have configured a custom trust store. I searched over the internet and someone suggested to put play.ws.ssl.loose.acceptAnyCertificate=true
in app conf but It wasn't working. Then i also tried running application with passing the arguments activator run -Dmail.smtp.ssl.trust=* -Dmail.smtp.ssl.checkserveridentity=false
which wasn't recommended but still result was failure.
Ok thanks for the information provided. What operating system and what version of the JRE are you using ? I will try to reproduce this issue on my machine.
No problem sure here are my version and other details details: Windows 10 Version 10.0.14393 Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Thanks for the the quick input!
Dayummm You won't believe it i was thinking and just hit in my mind that there could be one more thing that can cause trouble that is my antivirus blocking smtp requests. Guess what i was right. I deactivated my antivirus protection and it works like a charm!
Thanks @Mogztter agian for quick replies :). Actually i think it's better to add this in the README file for windows users that if mailer is not working try closing any antivirus shields that might can lead to block smtp requests.
Just for future reference for someone who might be wondering what were my working app conf for google smtp using TLS then it is as follows:
play.mailer {
host="smtp.gmail.com"
port=587
ssl=no
tls=yes
user="*******@gmail.com"
password="******"
debug=yes #for dev usage only
}
I'm glad you found the root cause.
Actually i think it's better to add this in the README file for windows users that if mailer is not working try closing any antivirus shields that might can lead to block smtp requests.
Yes, that's a good idea! I think we should add a troubleshooting section with the stack traces and the possible causes.
I also have been playing with mailer plugin but still i am having problem since 2 days i am stuck on just this simple task. Well reading other topics seems like other people are also have problems. So like them i also followed the same config as told in the installation in play-mailer page still not able to send any email. Here is my app configuration:
MailService Class wrapper (omitted importing libs just to keep the code minimal):
My controller action in the play framework:
and i getting these exceptions:
When i go for gmail config then my app config looks like this:
And exceptions:
Also i want to confirm something as i am using play without any SSL config so right now on my dev server i am accessing it locally on HTTP rather HTTPS. Does that matter that i have to be on HTTPS protocol to use this mailer plugin?