marko
marko

Reputation: 3776

Grails 2.1.1 sending mail

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?

Upvotes: 3

Views: 3195

Answers (1)

James Kleeh
James Kleeh

Reputation: 12228

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

class BootStrap 
{
    def mailService

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

Upvotes: 5

Related Questions