0

We have a scheduled invoicing service, where we send invoices to customers' email.

asynchronousMailService.sendMail {
            multipart true
            to emailTo.split("[,;]")
            bcc bccString
            from fromString
            subject subjectString
            html view:'/email/invoiceEmailTemplate',
                    model: [companyName: companyName, customerFirstName:  order.customer.firstName,
                            xeroInvoiceId: invoice.invoiceNumber, invoiceTotal: order.totalAmount,
                            invoiceUrl: invoiceUrl,
                            currencyCode: invoice.currencyCode, dueDate: invoice.dueDate]
            attachBytes invoice.invoiceNumber+".pdf" , 'application/pdf', invoiceBytes
        }

Causing this error:

2016-03-09 18:22:23,073 [quartzScheduler_Worker-10] ERROR listeners.ExceptionPrinterJobListener  - Exception occurred in job: Grails Job
        org.quartz.JobExecutionException: java.lang.NullPointerException [See nested exception: 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
                at java.net.URI$Parser.parse(URI.java:3023)
                at java.net.URI.<init>(URI.java:595)
                at grails.plugin.mail.MailMessageContentRenderer$PageRenderRequestCreator.createInstance(MailMessageContentRenderer.groovy:198)
                at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.init(MailMessageContentRenderer.groovy:147)
                at grails.plugin.mail.MailMessageContentRenderer$RenderEnvironment.with(MailMessageContentRenderer.groovy:178)
                at grails.plugin.mail.MailMessageContentRenderer.render(MailMessageContentRenderer.groovy:63)
                at grails.plugin.asyncmail.AsynchronousMailMessageBuilder.doRender(AsynchronousMailMessageBuilder.groovy:281)
                at grails.plugin.asyncmail.AsynchronousMailMessageBuilder.html(AsynchronousMailMessageBuilder.groovy:267)
                at com.mycompany.thirdparty.InvoiceService$_emailInvoiceToCustomer_closure5.doCall(InvoiceService.groovy:118)
                at grails.plugin.asyncmail.AsynchronousMailService.sendAsynchronousMail(AsynchronousMailService.groovy:21)
                at AsynchronousMailGrailsPlugin$_configureSendMail_closure9.doCall(AsynchronousMailGrailsPlugin.groovy:132)
                at com.mycompany.thirdparty.InvoiceService.emailInvoiceToCustomer(InvoiceService.groovy:112)
                at com.mycompany.thirdparty.InvoiceService$_createInvoice_closure2.doCall(InvoiceService.groovy:47)
                at grails.plugin.multitenant.core.MultiTenantService$_doWithTenantId_closure1_closure2.doCall(MultiTenantService.groovy:32)
                at grails.plugin.hibernatehijacker.template.HibernateTemplates$_withTransaction_closure1.doCall(HibernateTemplates.groovy:39)
                at grails.plugin.hibernatehijacker.template.HibernateTemplates.withTransaction(HibernateTemplates.groovy:37)
                at grails.plugin.multitenant.core.MultiTenantService$_doWithTenantId_closure1.doCall(MultiTenantService.groovy:31)
                at grails.plugin.hibernatehijacker.template.HibernateTemplates$_withNewSession_closure2.doCall(HibernateTemplates.groovy:65)
                at grails.plugin.hibernatehijacker.template.HibernateTemplates.withNewSession(HibernateTemplates.groovy:57)
                at grails.plugin.multitenant.core.MultiTenantService.doWithTenantId(MultiTenantService.groovy:30)
                at grails.plugin.multitenant.singledb.MtSingleDbPluginSupport$_createWithTenantIdMethod_closure2.doCall(MtSingleDbPluginSupport.groovy:141)
                at com.mycompany.thirdparty.InvoiceService.createInvoice(InvoiceService.groovy:38)
                at com.mycompany.thirdparty.InvoiceJob.execute(InvoiceJob.groovy:13)
                at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:102)

The above error logs only happen in production server and I have no success in replicating on my local machine and dev server.

Any ideas?

renz
  • 1,072
  • 3
  • 11
  • 21

1 Answers1

1

I answered that question once here: Grails Mail service not working with guartz scheduler in war mode

It's the AsyncMail unable to get the server's URL. The simplest thing is to configure it via the grails.serverURL config property.

Community
  • 1
  • 1
defectus
  • 1,947
  • 2
  • 16
  • 21