Latest Grails-mail plugin SVN commits fix GSP view rendering
The other day I committed some further improvements to the experimental email body rendering from GSP views. There is no release of grails-mail with this code in, you need to manually svn checkout and build it from the grails-plugins SVN repo.
Anyway, the fixes allow you to render email body GSPs where the GSP may live in a plugin, or be overriden by your app. To do this, you have to specify the plugin name when rendering the body of the mail – this is required because there’s currently no way Grails can know where the view might be as the contents of plugin view trees are not merged with the app view tree. I can see scope for a future improvement in Grails core, to add all plugin view paths to the resource search paths during development, and shipping a single merged views/ tree within .WAR files built by Grails.
So here’s how you render a mail body from a view in a controller with grails-mail installed:
sendMail {
to "test@somewhere.com"
subject "Hello"
body(view:'/something/mailbody1.gsp',
plugin:'my-great-plugin')
}
This will try to locate the view in:
<app>/grails-app/views/something/mailbody1.gsp
but if it can’t find it, will try:
<app>/plugins/my-great-plugin-<vernum>/grails-app/views/something/mailbody1.gsp
Also these commits fix GSP taglibs in email bodies. Previously they’d appear in the HTML response of the controller ooops… now they appear in the body of the mail as expected.
