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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With