email - grails 中的异步邮件插件实现

标签 email grails asynchronous

我正在尝试在 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/

相关文章:

Java - 从文件读取字节时对其进行处理

javascript - 如何等待数据有希望到来?

javascript - 从 JS 函数调用 NodeJS 函数

sql-server - 避免连接失败时出现空指针

security - Oauth2 使用 hd 限制具有特定域名的电子邮件不起作用

mysql - Grails 数据库迁移 : Convert xml/groovy diff into sql script file

node.js - 在 Amazon Lambda 示例中使用异步?

Python Pandas to_html 样式

php - 在heredoc/nowdoc语法中回显

java - 使用 Java 邮件服务器进行测试