Login required
Download

Asynchronous mail grails plugin

(5)
Author(s) Vitalii Samolovskikh aka Kefir
Current Release 0.4   (3 days ago)
Grails Version 2.0.0 > *
Tags asynchronous  mail 
Dependency
compile ":asynchronous-mail:0.4"
This plugin realise asynchronous mail sent. It place messages to DB and sent them by quartz job asynchronously.
Last updated by Kefir 2 years ago
grails install-plugin asynchronous-mail
Last updated by Kefir 1 month ago
Attention! The DB schema was changed since version 0.3. It was did for support Oracle DBMS.

The Grails Asynchronous Mail is a plugin for asynchronous sending of email messages. It persist email messages in DB and send them by scheduled job. It allow to react to user's actions faster. If SMTP server isn't available in time then plugin can sent message after, when server will be available.

Plugin depends by hibernate, quartz, mail plugins.

Configuration

Create AsynchronousMailConfig.groovy in grails-app/config directory.
grails install-asynchronous-mail-config
Or you can use default configuration. It dispose in 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.override=false    // since 0.2.0
asynchronous.mail.clear.after.sent=false    // since 0.2.0
  • asynchronous.mail.default.attempt.interval - the default repeat interval in milliseconds between sending attempts
  • asynchronous.mail.default.max.attempts.count - the default max attempts count per message
  • asynchronous.mail.send.repeat.interval - repeat interval in milliseconds between starts of SendJob, which send email messages
  • asynchronous.mail.expired.collector.repeat.interval - repeat interval in milliseconds between starts of ExpiredCollectorJob, which mark messages as EXPIRED if time for sent is expired.
  • asynchronous.mail.messages.at.once - max messages count which can be sent per time.
  • asynchronous.mail.send.immediately - if true (default) then run SendJob immediately after message creating. Since version 0.1.2.
  • asynchronous.mail.override - If true then override method sendMail of MailService in Grails mail plugin. Default is false. Since version 0.2.0
  • asynchronous.mail.clear.after.sent - If true then all messages will be deleted after sent. Default is false. Since version 0.2.0
Configure mail plugin. Asynchronous mail use mail plugin for sending messages.

Usage

If you use mail plugin already, you must inject asynchronousMailService or alias asyncmailService into your class:
import grails.plugin.asyncmail.AsynchronousMailService

AsynchronousMailService asynchronousMailService
or
AsynchronousMailService asyncMailService

AsynchronousMailService is a grails service.

And change your sendMail call to

asyncMailService.sendMail {
    // 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 delete true; // Mark message for delete after sent immediate true; // Send message immediately priority 10; // If priority greater then message send faster }

Override

You can override MailService and sendMail dynamic method for use Grails Asynchronous plugin with others plugins for example. Just add to configuration file:
asynchronous.mail.override=true
The Grails Asynchronous Mail plugin fully support futures of The Grails Mail plugin.

Indexes

I recommend to create an index on async_mail_mess.status column. It's result of my heuristic observations. Only DBA must create indexes anyway.

Support

You can report about bugs in the JIRA or ask me by email kefir@perm.ru.
Last updated by admin 2 years ago
Last updated by admin 2 years ago