New Grails Mail Plugin Wednesday, June 04, 2008

The new Grails Mail Plugin is really slick stuff. Very little effort has gone in to the thing so far and there is more to come but even in its current state this is really nice. More details are available at http://grails.org/Mail+Plugin but basically you get a method called 'sendMail' added to your controllers (or you could use an autowired mailService) that accepts a closure and the contents of the closure express the details of the message being sent. A simple example looks like this...


sendMail {
to 'fred@g2one.com'
subject 'Hello Fred'
body 'How are you?'
}


Take a look at the docs for more information. This is good stuff already. I think the simplicity of sending a message like this is pretty impressive but more impressive is how easy it is to build support for something like that in a dynamic language like Groovy. More and more folks are taking advantage of the Grails Plugin System to easily add capabilities like this to their web apps.

Enjoy!

4 comments:

Vijay said...

Great article Jeff,
Just one comment on building a "to" string, i.e. the list of email addresses to whom the email will be sent. If this is not a static list of email addresses (which would be the case in most situations), you need to pass a String[] to the "to" parameter. I tried to pass a list or a String it did not work.

Just my 2c.
Vijay Kumar

Pablo said...

Let me know if you can provide some information or mail me How do you set mailSession for JBOSS with new plugin creating a WAR. I will use smtp configuration in Jetty. I am not sure how to configure jndi in jetty

john said...

Very slick specially today. It can talk to any type of servers, from Gmail, Hotmail, MS Exchange, etc.

Naviya Nair said...

Interesting Article

Java Online Training from India | Core Java Training Online

Java Online Training | Java EE Online Training