Grails 2.1.1 sending mail

3.2k Views Asked by At

I installed the mail plugin:

grails install-plugin mail

I added my config according to the plugin:

grails {
    mail {
      host = "smtp.gmail.com"
      port = 465
      username = "[email protected]"
      password = "yourpassword"
      props = ["mail.smtp.auth":"true",
               "mail.smtp.socketFactory.port":"465",
               "mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
               "mail.smtp.socketFactory.fallback":"false"]
    }
}

I added a sendMail to my Bootstrap.groovy

try{
 sendMail {
  from "[email protected]"
  to "[email protected]"
  subject "Hello"
  body "Mail"
 }
}catch (Exception e){
 println e
}

And it gives me nothing! I have tried juggling with the location in the Config.groovy and more things - nothing! It doesn't even give me an exception.

Any ideas?

1

There are 1 best solutions below

1
On BEST ANSWER

You need to inject the mail service. In your Bootstrap.groovy:

class BootStrap 
{
    def mailService

    def init = { servletContext ->
        mailService.sendMail {
        }
    }
}