问题
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