首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Grails,ORM,Quartz,Jobs,

Grails,ORM,Quartz,Jobs,
EN

Stack Overflow用户
提问于 2016-04-15 23:32:11
回答 2查看 121关注 0票数 0

我正在使用Grails 3.0.12,我正在使用Quartz执行作业,我现在尝试做的是每次(在本例中是每5秒)发送一封电子邮件。我的服务文件夹中有电子邮件服务。这是我的代码:

代码语言:javascript
复制
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 "xxxxxx@gmail.com"
            subject "hello"
            body "hello"
        }
    }
}
}   

我试图创建一个服务类的实例来调用mailService.sendMail,但没有成功。

非常感谢你的帮助。:)

EN

回答 2

Stack Overflow用户

发布于 2016-04-15 23:50:41

看起来你正在尝试在你的工作中使用邮件插件,但是你还没有将邮件服务注入到你的工作中。

添加:

代码语言:javascript
复制
def mailService

添加到您的类,它将被注入并可用。有关服务注入的更多信息,可以在这里找到https://grails.github.io/grails-doc/latest/guide/single.html#dependencyInjectionServices

有关配置和使用邮件插件的更多信息在此处- https://grails.org/plugins.html#plugin/mail

票数 2
EN

Stack Overflow用户

发布于 2018-03-17 14:09:39

下面是我如何做类似的事情,使用@Scheduled注释从目录中的文件发送电子邮件。

代码语言:javascript
复制
EmailService emailService

static boolean lazyInit = false 
@Scheduled(fixedDelay = 3000L, initialDelay = 2000L) 
void executeEveryFourtyFive() {


dire = new File(configfilepath)
dire.eachFileRecurse (FileType.FILES) { fileEmail ->
listEmail << fileEmail
}

listEmail.each {
filepath = it.path
sourceFolder = new File(filepath) 

   if (sourceFolder.exists()){  
    String fileContents = new File(filepath).text
       def emailaddress = emailaddress

    def emailmessage = message
    def emailtitle = title

    def emailsubject = subject
    def emailfrom = emailfrom
 emailService.send(emailaddress,emailmessage,emailsubject...)
   }
 }
 }catch(Exception exc){
      exc.printStackTrace()
    }
  }else{
   println "++++++++++email service off++++++++++"
 }
 }

然后我有我的emailService来做剩下的事情。希望这能帮助到别人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36651292

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档