3

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 = "youraccount@gmail.com"
      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 "youraccount@gmail.com"
  to "youraccount@gmail.com"
  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?

marko
  • 3,736
  • 6
  • 29
  • 46

1 Answers1

5

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

class BootStrap 
{
    def mailService

    def init = { servletContext ->
        mailService.sendMail {
        }
    }
}
James Kleeh
  • 12,094
  • 5
  • 34
  • 61
  • 1
    Thanks! I saw that option in the documentation but I thought it was the equivalent of just using sendMail. Thanks!!!! – marko Dec 04 '12 at 22:30