2

I have this plugin installed, I want to send mails from a Service/Domain class method , I was doing like this

   class TrainingService {
      def mailService
      public def sendMail() {
        mailService.sendMail {
            multipart true
            to "abc@xyz.com"
            subject "Hello,"
            body 'How are you?'

          }
}

I got error "Cannot invoke method sendMail() on null object", How to resolve this

4

3 回答 3

1

我缺少“发件人”属性,如果您使用的是多部分电子邮件,您还应该填写电子邮件的其他部分,我的代码片段:

mailService.sendMail {
            multipart true
            from '"Some account" <someaccount@email.com>'
            to 'anotheremail@somedomain.com'
            bcc emailAddresses.toArray()
            subject dto.title
            body emailPart1
            html g.render(
                    template: 'emailNotification',
                    model: [ name: dto.name ]
            )

}
于 2012-07-18T11:14:58.937 回答
0

您是否配置了 SMTP 服务器。您需要配置文件中的这些条目才能使邮件正常工作。你有这些吗?

grails {
    mail {
                    host = "hostname"
                    pop_port = 25
                    username = "username"
                    password = "password"
                    type = "pop3"

                }
}

您可以在此处找到有关配置的更多信息

于 2012-07-18T15:19:24.283 回答
0

当我将名为“from”和“to”的变量传递给使用 sendMail 的方法时,出现此错误。尝试重命名 sendMail 方法并确保您没有任何冲突的变量名称。

于 2015-09-18T09:18:37.230 回答