grails异步邮件服务错误

时间:2015-06-14 02:33:20

标签: email session grails asynchronous quartz-scheduler

我们的系统使用asynchronousMailService

在Job中发送电子邮件
log.debug 'Sending email to ' + emailTo
asynchronousMailService.sendMail {
    multipart true
    to emailTo.split("[,;]")
    bcc "test@bcc.com"
    from "test@from.com"
    subject "test subject"
    html(view:'/email/testTemplate', model: [test:  test])
    attachBytes testId +".pdf" , 'application/pdf', invoiceBytes
}
log.debug("Invoice email sent.")

使用以下grails config:

grails {
    mail {
        host = "smtp.gmail.com"
        port = 465
        username = "test@test.com"
        password = "password"
        props = ["mail.smtp.auth":"true",
                "mail.smtp.socketFactory.port":"465",
                "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
                "mail.smtp.socketFactory.fallback":"false"]

    }
}

asynchronous.mail.default.attempt.interval = 300000l       // Five minutes
asynchronous.mail.default.max.attempts.count = 1
asynchronous.mail.send.repeat.interval = 60000l           // One minute
asynchronous.mail.expired.collector.repeat.interval = 607000l
asynchronous.mail.messages.at.once = 100
asynchronous.mail.send.immediately = true
asynchronous.mail.override = false
asynchronous.mail.clear.after.sent = false
asynchronous.mail.disable = false
asynchronous.mail.useFlushOnSave = true
asynchronous.mail.persistence.provider = 'hibernate4'      // Possible values are 'hibernate', 'hibernate4', 'mongodb'
asynchronous.mail.gparsPoolSize = 1
asynchronous.mail.newSessionOnImmediateSend = false

只要成功发送电子邮件,我就会看到这些日志:

2015-06-14 12:04:11,107 [ForkJoinPool-4071-worker-1] DEBUG asyncmail.AsynchronousMailProcessService  - Open new session.
2015-06-14 12:04:17,101 [ForkJoinPool-4071-worker-1] DEBUG asyncmail.AsynchronousMailProcessService  - Flush the session.
2015-06-14 12:04:17,101 [ForkJoinPool-4071-worker-1] DEBUG asyncmail.AsynchronousMailProcessService  - Destroy the session.
2015-06-14 12:04:17,101 [ForkJoinPool-4071-worker-1] DEBUG asyncmail.AsynchronousMailProcessService  - Open new session.
2015-06-14 12:04:23,125 [ForkJoinPool-4071-worker-1] DEBUG asyncmail.AsynchronousMailProcessService  - Flush the session.
2015-06-14 12:04:23,125 [ForkJoinPool-4071-worker-1] DEBUG asyncmail.AsynchronousMailProcessService  - Destroy the session.

但是,在某些情况下,它不会发送电子邮件,并且日志中没有打开/刷新/销毁会话。

当我查看数据库中的async_mail_mess表时,我可以看到该电子邮件条目具有 ERROR 状态。

我不确定是什么导致了这种间歇性错误,并且无法从日志中看到任何堆栈跟踪。我应该增加最大尝试次数吗?如何捕捉这些错误?

1 个答案:

答案 0 :(得分:0)

插件在发送消息之后将消息状态更改为ERROR,之后将状态更改为SENT。在系统被粉碎的情况下,需要防止双重发送。看起来你看到现在发送的消息。