Using GSPs with Mail plugin

View: New views
4 Messages — Rating Filter:   Alert me  

Using GSPs with Mail plugin

by DaveKlein :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,

I'm using GSPs as the body of mail messages with the mail plugin and it works great as long as the GSPs are in the standard view folders.  I would like to put them somewhere else but I can't seem to make that work.  I've tried putting them in a folder along side the js and css, etc.  and I've tried putting them in a folder inside WEB-INF (based on an example found on the net), and I tried putting them in an unrelated folder on the file system.  Then I try every way I can think of to refer to the beasts and they still come up not found.  I've tried absolute paths, relative paths, with .gsp, without .gsp,

I was just wondering if anyone else had done this and would be willing to share their secrets.

Thanks a bunch,
Dave





--
Grails: A Quick-Start Guide
http://pragprog.com/titles/dkgrails
http://gquick.blogspot.com

Re: Using GSPs with Mail plugin

by Peter Ledbrook :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I was just wondering if anyone else had done this and would be willing to
> share their secrets.

I can only think of using shared templates (which you're probably
using and still rely on the GSPs being under grails-app/views). This
is line 581 of RenderTagLib as it currently stands:

    t = engine.createTemplateForUri(["${contextPath}${uri}",
"${contextPath}/grails-app/views/${uri}"] as String[])

I guess you could use your own instance of the Groovy Pages template engine.

Cheers,

Peter

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Using GSPs with Mail plugin

by DaveKlein :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, it turns out having the GSPs in grails-app/views is no problem.  So, all was well... until I realized that this code needs to be in a service.  So, I'm back to the same problem.  According to the docs, when not calling the mailService.sendMail() from a controller, you need to use the absolute path.  And I'm having the same problem.  It will not recognize the GSP with an absolute path. 

So, what's the magic incantation to use a GSP while calling the mailService from another service? 

Thanks,
Dave


Re: Using GSPs with Mail plugin

by Deluan Cotts Quintao :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Dave,

A while ago I worked on a project that needed exactly this: Sending email created from GSP templates. After a lot of research and tests, I came up with the service that I've attached to this email. It works perfectly, as long as the templates are stored in grails-app/views.

What I've done was to separate the template processing from the mail sending, so this service is only for the first part of the process. You can then use mailService.sendMail(), passing the result of this service to the html or body methods.

Just note that this service was only tested with Grails 1.0.3. Maybe there is a simpler (and Groovier) way to do this, but at least it works :)

Regards,
Deluan

DaveKlein wrote:
Hi All,

I'm using GSPs as the body of mail messages with the mail plugin and it
works great as long as the GSPs are in the standard view folders.  I would
like to put them somewhere else but I can't seem to make that work.  I've
tried putting them in a folder along side the js and css, etc.  and I've
tried putting them in a folder inside WEB-INF (based on an example found on
the net), and I tried putting them in an unrelated folder on the file
system.  Then I try every way I can think of to refer to the beasts and they
still come up not found.  I've tried absolute paths, relative paths, with
.gsp, without .gsp,

I was just wondering if anyone else had done this and would be willing to
share their secrets.

Thanks a bunch,
Dave





--
Grails: A Quick-Start Guide
http://pragprog.com/titles/dkgrails
http://gquick.blogspot.com
EmailTemplateService.groovy