0
我正在使用Grails 3.0.12,我正在使用Quartz來執行一項工作,我現在要做的就是每次發送一封電子郵件(在這種情況下,每5個秒)。我的服務文件夾中有電子郵件服務。這是我的代碼:Grails,ORM,Quartz,Jobs,
class EnviaCorreosJob{
NotifierService notificar
Integer diasParaCorreo = 30
static triggers =
{
cron name: 'myTrigger', cronExpression: "*/5 * * * * ?"
}
def group = "MyGroup"
def description = "Example job with Cron Trigger"
def fechaHoy = new Date()
def execute()
{
println "------------------ Running every 5 seconds -------------------"
def queryAgenda = Agenda.where
{
inicio_cita <= (fechaHoy + diasParaCorreo)
}
def listaAgenda = queryAgenda.list()
println "----------------------Dates list : " + listaAgenda
log.info "listaAgenda: " + listaAgenda
log.info "listaAgendaTamaño: " + listaAgenda.size()
listaAgenda.each
{
agenda ->
println "it's inside"
mailService.sendMail
{
to "[email protected]"
subject "hello"
body "hello"
}
}
}
}
我試圖讓一個Service類的實例調用mailService.sendMail但沒有工作。
非常感謝您的幫助。 :)
我已經添加了高清** ** MailService的,但現在這是錯誤 組織。 quartz.JobExecutionException:java.lang.NullPointerException:無法在null對象上調用方法sendMail() – R2R
您實際上是否在'build.gradle'中定義了郵件插件?你能舉一個完整的例子嗎? – erichelgeson
是的,但是我的錯誤,你是對的,我移動了一些代碼和** def mailService **是我應該先放的正確的東西。 非常感謝。 :) – R2R