Our system is sending an email inside a Job using asynchronousMailService
log.debug 'Sending email to ' + emailTo
asynchronousMailService.sendMail {
multipart true
to emailTo.split("[,;]")
bcc "[email protected]"
from "[email protected]"
subject "test subject"
html(view:'/email/testTemplate', model: [test: test])
attachBytes testId +".pdf" , 'application/pdf', invoiceBytes
}
log.debug("Invoice email sent.")
with the following grails config:
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "[email protected]"
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
I see these logs whenever it successfully sends emails:
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.
However, in some instances, it doesn't send the email and there's no open/flush/destroy session in the logs.
When I look at the async_mail_mess
table in the database, I can see there that the email entry has ERROR status.
I'm not sure what's causing this intermittent error and can't see any stacktrace from the logs. Should I increase max attempt count? How to catch these errors?
The plugin changes the message status to ERROR before sending the message after that it changes the STATUS to SENT. It's needed to prevent double sending in case of the system is crushed. Looks like you see messages which are sent right now.