What is the best way to generate HTML mail templates for the Grails mail plugin?

巧了我就是萌 提交于 2019-12-11 13:32:11

问题


With the Grails Mail plugin you can either send plain text or html mails. When sending html mails like this:

sendMail {
  to "fred@g2one.com"
  subject "Hello John"
  html(view: htmlTemplate, model: args)   
}

It is recommended to make css inline in mail html, because it will be accepted by more mail clients. The problem is, that these html files are hard to read and maintain.

Is there a way to generate these mail templates in a smarter way than writing inline css? What is a best practice to generate html mail templates?


回答1:


Templates can include other templates using the g:render tag.

If you don't want the inline css mixed with your mail html, place it in its own template and use the render tag to insert it into the html template:

mail/_css.gsp:

<style type="text/css">
    body {
      /* styles! */
    }
</style>

mail/_message.gsp:

<html>
    <head>
        <g:render template="/mail/css" /> <!-- render stylesheet into this template -->
    </head>
    <body>
        <!-- content -->
    </body>
</html>



回答2:


I created a gist on how to do it following a good pattern.

https://gist.github.com/biniama/7ec152189512c318c6fa



来源:https://stackoverflow.com/questions/16916346/what-is-the-best-way-to-generate-html-mail-templates-for-the-grails-mail-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!