Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous Mail Plugin implementation in grails

I am trying to implement Asynchronous Mail Plugin in Grails project. I have followed all steps of This Tutorial

In this I am not able to inject asyncMailService object into me controller class. Import to

import grails.plugin.asyncmail.AsynchronousMailService

not recognized.

Here is my code for sending mail :

AsynchronousMailService asyncMailService asyncMailService.sendMail { to '[email protected]' subject 'Test'; html '<body><u>Test</u></body>'; }

In above code AsynchronousMailService is not recognized.

I am able to send mail using below code :

sendMail { to '[email protected]' subject 'Test'; html '<body><u>Test</u></body>'; }

But this is not sending mail asynchronously. I want to send mail asynchronously.

Please tell me what I am doing wrong in this.

Thanks.

like image 578
mark Avatar asked Apr 27 '26 02:04

mark


1 Answers

I suspect it's because you aren't injecting the service correctly. Your controller should look something like this:

package com.example
import grails.plugin.asyncmail.AsynchronousMailService

class MyController {

  AsynchronousMailService asyncMailService // this injects the service

  def someFancyMethod() {
    ...
    asyncMailService.sendMail {
      to '[email protected]'
      subject 'Test';
      html '<body><u>Test</u></body>';
    }
    ...
  }
}

Notice that you are injecting the service outside the method.

like image 151
Joshua Moore Avatar answered Apr 30 '26 15:04

Joshua Moore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!