Question

I'm trying to send an email using Play Framework and SendGrid in Heroku. I set the configuration (Application.conf) as follows:

mail.smtp=smtp
mail.smtp.host=smtp.sendgrid.net
mail.smtp.port=587
mail.smtp.user=${SENDGRID_USERNAME}
mail.smtp.pass=${SENDGRID_PASSWORD}
mail.smtp.protocol=smtps
mail.smtp.channel=plain
mail.debug=true

but I get this exception:

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at javax.mail.Session.getService(Session.java:760)
    at javax.mail.Session.getTransport(Session.java:689)
    at javax.mail.Session.getTransport(Session.java:632)
    at javax.mail.Session.getTransport(Session.java:612)
    at javax.mail.Session.getTransport(Session.java:667)
    at javax.mail.Transport.send0(Transport.java:148)
    at javax.mail.Transport.send(Transport.java:80)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at play.libs.Mail$2.call(Mail.java:180)
    at play.libs.Mail$2.call(Mail.java:175)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.SecurityException: class "com.sun.mail.util.PropUtil"'s signer information does not match signer information of other classes in the same package
    at java.lang.ClassLoader.checkCerts(ClassLoader.java:806)
    at java.lang.ClassLoader.preDefineClass(ClassLoader.java:487)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:625)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at com.sun.mail.smtp.SMTPTransport.<init>(SMTPTransport.java:146)
    at com.sun.mail.smtp.SMTPTransport.<init>(SMTPTransport.java:133)
    ... 20 more
ERROR  niceThrowable, 

@68efkgai3
The email has not been sent

Mail error
A mail error occured : Error while sending email

play.exceptions.MailException: Error while sending email
    at play.libs.Mail$2.call(Mail.java:183)
    at play.libs.Mail$2.call(Mail.java:175)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.sendgrid.net:25
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at play.libs.Mail$2.call(Mail.java:180)
    ... 6 more
Caused by: javax.mail.NoSuchProviderException: smtp
    at javax.mail.Session.getService(Session.java:764)
    at javax.mail.Session.getTransport(Session.java:689)
    at javax.mail.Session.getTransport(Session.java:632)
    at javax.mail.Session.getTransport(Session.java:612)
    at javax.mail.Session.getTransport(Session.java:667)
    at javax.mail.Transport.send0(Transport.java:148)
    at javax.mail.Transport.send(Transport.java:80)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
    ... 8 more

Debugging the Mail.java class in Play, it seems to set the parameters properly. Anyone that has make it work can share his/her configuration?

Was it helpful?

Solution 3

Ok, found it. The issue was that a module I am using had a non-dependency-managed copy of mail.jar (the Java mail api). As Play embeds it's own copy, this caused a conflict which resulted in the "cryptic" error:

Caused by: javax.mail.NoSuchProviderException: smtp

Another argument in favour of using dependencies.yml for your modules, guys!

Thanks to everybody who answered for the answers, they helped somehow :)

OTHER TIPS

Maybe you also need:

mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.smtp=smtp

should be commented out if you are using the other settings I believe. It looks like this is your error based on the stack trace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top