Grails 如何发送带有布局的电子邮件

Grails 如何发送带有布局的电子邮件,grails,smtp,Grails,Smtp,我正在使用grails邮件插件。当我提交表格时,它将从发送电子邮件aaa@example.comto textField name=“成功发送电子邮件,但我如何发送具有布局的电子邮件…而不是像此图片或某些CSS那样空白 表格 <g:form action="send"> <table style="width:500px"> <tbody> <tr> <td>Your Email Address </td>

我正在使用grails邮件插件。当我提交表格时,它将从发送电子邮件aaa@example.comto textField name=“成功发送电子邮件,但我如何发送具有布局的电子邮件…而不是像此图片或某些CSS那样空白

表格

<g:form action="send">
<table style="width:500px">
<tbody>
<tr>
   <td>Your Email Address  </td>
       <td><g:textField style="width:250px" name = "email"/></td>
</tr>
<tr>
   <td>Your Name</td>
       <td><g:textField style="width:250px" name = "user"/></td>
</tr>
<tr>
   <td><input type="submit"/></td>
</tr>
</tbody>
</table>
</g:form>

它不会选择grails布局。你也不希望这样。你应该以一种方式构建你的电子邮件,它可以是一个独立的网页,没有其他依赖项。使用的所有静态资源都应该可以通过公共URL访问。

实际上,你可以使用电子邮件布局,类似于使用layouts用于查看页面。您要做的是为电子邮件正文内容创建一个新的布局和视图文件

布局:例如./views/layouts/emailLayout.gsp

<%@ page contentType="text/html" %>
<html>
<head>
   <meta name="viewport" content="width=device-width" />
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <style>
       a {color: #348eda;}
   </style>
 </head>
 <body>
    <g:layoutBody/>
 </body>
</html>

嗯…我不明白..你能给我看一点编码吗?或者我该怎么做..因为这是电子邮件正文中唯一的布局..如果我输入我的电子邮件..那么服务器会给我发送带有正文布局的电子邮件..我不确定如何让我的答案更清楚。你知道如何创建静态HTML页面吗?创建静态HTML页面,将其放入/user/layoutmail.gsp和您的sendMail将发送它。当您说“layout”时,可能我误解了您。是的,请查看以下代码:body(视图:“/user/layoutmail”,model:[name:params.user])…“layoutmail.gsp”,当我发送到我的电子邮件时..它填充了layoutmail的编码..示例等
<%@ page contentType="text/html" %>
<html>
<head>
   <meta name="viewport" content="width=device-width" />
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <style>
       a {color: #348eda;}
   </style>
 </head>
 <body>
    <g:layoutBody/>
 </body>
</html>
<%@ page contentType="text/html" %>
<g:applyLayout name="emailLayout">
<html>
<body
   <a href="${welcome.url}">Your Welcome ${welcome.username}</a>
</body>
</html>
</g:applyLayout>
def sendWelcomeMail(User user, String url){
    def rtn = [success:false]
    if(user) {
        def fooBar = [
                username: user.username,
                email: user.email,
                url: url
        ]
        sendMail {
            async true
            to fooBar.email.trim()
            subject "Welcome Email"
            body(view: '/emails/welcomeEmail', model: [welcome: fooBar])
        }
        rtn.success = true
    }
    return rtn
}