I'm trying to decouple the sending of notification emails from the events that cause them. So far I'm passing a mail object (DocumentIssuedMail
) from a controller to an Akka actor(EmailDispatcher
), which is then sending the mail via the play-easymail wrapper of the Play mailer plugin. The email body is generated by the mail object after being passed to the actor, and the HTML is generated from a Scala template.
This template contains link with absolute URLs, obtained by calling
@routes.SomeController.someAction().absoluteURL()
However, I'm getting a RuntimeException when trying to render the template.
The stack trace is as follows:
java.lang.RuntimeException: There is no HTTP Context available from here.
at play.mvc.Http$Context.current(Http.java:30)
at play.mvc.Http$Context$Implicit.ctx(Http.java:196)
at play.core.j.PlayMagicForJava$.requestHeader(TemplateMagicForJava.scala:56)
at views.html.email._learner_main$.apply(_learner_main.template.scala:41)
at views.html.documents.email.new_doc_unregistered$.apply(new_doc_unregistered.template.scala:47)
at views.html.documents.email.new_doc_unregistered$.render(new_doc_unregistered.template.scala:67)
at views.html.documents.email.new_doc_unregistered.render(new_doc_unregistered.template.scala)
at email.DocumentIssuedMail.getUnregisteredMail(DocumentIssuedMail.java:71)
at email.DocumentIssuedMail.getMail(DocumentIssuedMail.java:67)
at actors.email.EmailDispatcher.onReceive(EmailDispatcher.java:32)
at akka.actor.UntypedActor$$anonfun$receive$1.applyOrElse(UntypedActor.scala:167)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:498)
at akka.actor.ActorCell.invoke(ActorCell.scala:456)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237)
at akka.dispatch.Mailbox.run(Mailbox.scala:219)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Is it possible to render the template in that location, or do I need to do it on the original thread?