grails / grails-mail

The Grails Mail Plugin
https://grails.github.io/grails-mail/
Apache License 2.0
14 stars 25 forks source link

Can't send Message with view from quartz job (Grails 3.1.3) #14

Closed AlexKovynev closed 7 years ago

AlexKovynev commented 8 years ago

With 3.1.0 it's all ok.

ERROR grails.plugins.quartz.listeners.ExceptionPrinterJobListener - Exception occurred in job: Grails Job
org.quartz.JobExecutionException: java.lang.NullPointerException
        at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:111)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: java.lang.NullPointerException: null
        at java.net.URI$Parser.parse(URI.java:3042)
        at java.net.URI.<init>(URI.java:588)
        at grails.plugins.mail.MailMessageContentRenderer$PageRenderRequestCreator.createInstance(MailMessageContentRenderer.groovy:192)
        at grails.plugins.mail.MailMessageContentRenderer$RenderEnvironment.init(MailMessageContentRenderer.groovy:141)
        at grails.plugins.mail.MailMessageContentRenderer$RenderEnvironment.with(MailMessageContentRenderer.groovy:172)
        at grails.plugins.mail.MailMessageContentRenderer.render(MailMessageContentRenderer.groovy:57)
        at grails.plugins.mail.MailMessageContentRenderer$render.call(Unknown Source)
        at grails.plugins.mail.MailMessageBuilder.doRender(MailMessageBuilder.groovy:276)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
        at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
        at grails.plugins.mail.MailMessageBuilder.html(MailMessageBuilder.groovy:294)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1426)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
        at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:384)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
        at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:69)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
        at sklad.SendbirthJob$_execute_closure1$_closure3.doCall(SendbirthJob.groovy:28)
delsner commented 8 years ago

I have the same Problem on Grails 3.1.3! Have you found any workaround yet?

AlexKovynev commented 8 years ago

Unfortunately not, the plugin developer does not respond to errors :( graemerocher save us!:)

AlexKovynev commented 8 years ago

I find workaround! Set grails.serverURL in config (for development enviroment too - "http://localhost:8080" )

alexkramer commented 8 years ago

I had this same issue when sending an email from a JMS listener. I was able to workaround it without needing to set the grails.serverURL. I injected the groovyPageRenderer and rendered the email template myself and passed the string value to the html parameter of the sendMail closure. Below is an example of how I was able to accomplish it with some hand waving (I am obviously missing all of the jms annotations and static methods)

import grails.gsp.PageRenderer

class SomeJmsListenerService {

    def mailService
    PageRenderer groovyPageRenderer

    def onMessage(String jsonMessage) {
        String emailTemplate = groovyPageRenderer.render([view: "/email/_emailTemplate", model: [userName: "Bob"]])
        mailService.sendMail {
            to "bob@somemailserver.com"
            subject "Hello Bob"
            html emailTemplate
        }
    }
}
sudosandwich3 commented 7 years ago

There may still be an issue in war deployments. Looks like it is looking for gsp files under: '/WEB-INF/grails-app/views' when the files are located in '/WEB-INF/classes'

tkvw commented 7 years ago

Created a PR for this: https://github.com/grails3-plugins/mail/pull/24

sbglasius commented 7 years ago

PR #24 was merged. Closing this issue