为Grails邮件插件生成HTML邮件模板的最佳方式是什么? [英] What is the best way to generate HTML mail templates for the Grails mail plugin?

查看:77
本文介绍了为Grails邮件插件生成HTML邮件模板的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Grails 邮件插件,您可以发送纯文本或html邮件。当发送像这样的HTML邮件时:

  sendMail {
到fred@g2one.com
主题Hello John
html(view:htmlTemplate,model:args)
}

建议在mail html中内联css,因为它会被更多的邮件客户端所接受。问题是,这些html文件很难读取和维护。



有没有比编写内联css更聪明的方式生成这些邮件模板的方法?生成html邮件模板的最佳实践是什么?

模板可以包含其他使用 g :render 标记。



如果您不想将内联css与您的mail html混合,请将它放在自己的模板中,并使用render标签插入到html模板中:



mail / _css.gsp:

 < style type =text / css> 
body {
/ *样式! * /
}
< / style>

mail / _message.gsp:

 < HTML> 
< head>
< g:render template =/ mail / css/> <! - 将样式表呈现到此模板中 - >
< / head>
< body>
<! - - 内容 - >
< / body>
< / html>


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?

解决方案

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>

这篇关于为Grails邮件插件生成HTML邮件模板的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆