java - Unable to send async emails with Play 2.5 -


i migrated application play 2.3 play 2.5 following guide https://www.playframework.com/documentation/2.5.x/migration25 , update play-mailer according specified here https://github.com/playframework/play-mailer

now app no longer able send emails. created injector constructor injecting mailer instance

@inject public smtpconnector(mailerclient mailer)  {      this.mailerclient = mailer;      mailcapcommandmap mc = (mailcapcommandmap)   mailcapcommandmap.getdefaultcommandmap();      mc.addmailcap("text/html;; x-java-content-  handler=com.sun.mail.handlers.text_html");      mc.addmailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");      mc.addmailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");      mc.addmailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");     mc.addmailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");     commandmap.setdefaultcommandmap(mc);  } 

i execute send email method in async task:

completablefuture.runasync( () -> mailerclient.send(email) ).exceptionally(exc -> {exc.printstacktrace(); return null;}); 

but keep getting error lack of suport mimetype multipart:

... java.util.concurrent.completablefuture$asyncrun.run(completablefuture.java:1626) ... 5 more caused by: javax.mail.messagingexception: ioexception while sending message; nested exception is: javax.activation.unsupporteddatatypeexception: no object dch mime type multipart/alternative; boundary="----=_part_0_1284684208.1469102367572" @ com.sun.mail.smtp.smtptransport.sendmessage(smtptransport.java:1177) @ javax.mail.transport.send0(transport.java:195) @ javax.mail.transport.send(transport.java:124) @ org.apache.commons.mail.email.sendmimemessage(email.java:1411) ... 14 more caused by: javax.activation.unsupporteddatatypeexception: no object dch mime type multipart/alternative; boundary="----=_part_0_1284684208.1469102367572" @ javax.activation.objectdatacontenthandler.writeto(datahandler.java:896) @ javax.activation.datahandler.writeto(datahandler.java:317) @ javax.mail.internet.mimebodypart.writeto(mimebodypart.java:1485) @ javax.mail.internet.mimemessage.writeto(mimemessage.java:1773) @ com.sun.mail.smtp.smtptransport.sendmessage(smtptransport.java:1121) ... 17 more

but:

is there workaround this? there a(nother) way send emails using java api play framework 2.5?

update 1:

according jmehrens suggestion, activated debug flag, that's got:

can't load dch com.sun.mail.handlers.multipart_mixed; exception: java.lang.classnotfoundexception: com/sun/mail/handlers/multipart_mixed

and according github.com/playframework/play-mailer/issues/104 problem seems triggered not calling method context of play controller

update 2: here can find -verbose:class output start till exception: s000.tinyupload.com/?file_id=50323853839855936002

update 3:

here can find classloader of getclass() dumped suggested jmehrens: s000.tinyupload.com/?file_id=51200633758480523188

this fixes issue:

completablefuture.runasync( () -> { thread.currentthread().setcontextclassloader( getclass().getclassloader() );  mailerclient.send(email);}, executors.newsinglethreadexecutor()).exceptionally(exc ->  { exc.printstacktrace();  return null;}); 

Comments