我正在尝试在 Grails 项目中实现异步邮件插件。我已按照 This Tutorial 的所有步骤进行操作
在这种情况下,我无法将 asyncMailService 对象注入(inject)到我的 Controller 类中。导入到
import grails.plugin.asyncmail.AsynchronousMailService
无法识别。
这是我发送邮件的代码:
AsynchronousMailService asyncMailService
asyncMailService.sendMail {
to 'xxx@gmail.com'
subject 'Test';
html '<body><u>Test</u></body>';
}
在上面的代码中AsynchronousMailService
无法识别。
我可以使用下面的代码发送邮件:
sendMail {
to 'xxx@gmail.com'
subject 'Test';
html '<body><u>Test</u></body>';
}
但这不是异步发送邮件。我想异步发送邮件。
请告诉我我做错了什么。
谢谢。
最佳答案
我怀疑这是因为您没有正确注入(inject)服务。您的 Controller 应如下所示:
package com.example
import grails.plugin.asyncmail.AsynchronousMailService
class MyController {
AsynchronousMailService asyncMailService // this injects the service
def someFancyMethod() {
...
asyncMailService.sendMail {
to 'xxx@gmail.com'
subject 'Test';
html '<body><u>Test</u></body>';
}
...
}
}
请注意,您正在方法之外注入(inject)服务。
关于email - grails 中的异步邮件插件实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22809501/