Asynchronous mail is a plugin for asynchronous mail messages sent. It persist mail messages in DB and send them in scheduled job. It allow to react to user's actions faster. If SMTP server can't be available in time then plugin can be sent message after, when server will be available.
Plugin depends by
hibernate,
quartz,
mail plugins.
Configuration
Create
AsynchronousMailConfig.groovy at
grails-app/config directory.
grails install-asynchronous-mail-config
Or you can use default configuration. It dispose at
plugin-dir/grails-app/conf/DefaultAsynchronousMailConfig.groovy .
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 // since 0.1.2
-
asynchronous.mail.default.attempt.interval - default repeat interval in milliseconds between send attempts
-
asynchronous.mail.default.max.attempts.count - default max attempts count per message
-
asynchronous.mail.send.repeat.interval - repeat interval in milliseconds between starts of send job, which send mail messages
-
asynchronous.mail.expired.collector.repeat.interval - repeat interval in milliseconds between starts of expired collector job, which mark messages as EXPIRED if time for sent is expired.
-
asynchronous.mail.messages.at.once - max messages count which can be sent at once.
-
asynchronous.mail.send.immediately - if true (default) then run send job immediately after message creating. Since version 0.1.2.
Configure
mail plugin. Asynchronous mail use
mail plugin for sending messages.
Usage
If you use
mail plugin already, you must
inject
asynchronousMailService into your class:
AsynchronousMailService asynchronousMailService
AsynchronousMailService is a grails service.
And change your
sendMail call to
asynchronousMailService.sendAsynchronousMail {
// Mail parameters
to 'kefir@perm.ru'
subject 'Test';
html '<body><u>Test</u></body>';
attachBytes 'test.txt', 'text/plain', byteBuffer; // Additional asynchronous parameters (optional)
beginDate new Date(System.currentTimeMillis()+60000) // Starts after one minute, default current date
endDate new Date(System.currentTimeMillis()+3600000) // Must be sent in one hour, default infinity
maxAttemptsCount 3; // Max 3 attempts to send, default 1
attemptInterval 300000; // Minimum five minutes between attempts, default 300000 ms
}
Indexes
I recommend create index on asynchronous_mail_message.status column. It's result of my heuristic observations. DBA must create indexes anyway.
Compatibility
I test version 0.1.0 with grails 1.1.2 and version 0.1.1 with grails 1.2.1. It works.
Support
You can report about bugs in the
JIRA or ask me by mail
kefir@perm.ru (Russian language is preferable :-)).