【问题标题】:How format email body in grails?如何在 grails 中格式化电子邮件正文?
【发布时间】:2014-12-22 18:53:17
【问题描述】:

我想使用我的 grails 应用程序发送电子邮件。它工作正常,但我需要的是我想用粗体、斜体、项目符号列表、文本颜色等格式化电子邮件正文。我尝试使用像

这样的 html 标记
      <strong> Hello </strong>  

为粗体

 <br>

用于线闸等。但收到的邮件内容显示html代码本身。我怎么能解决这个问题?提前致谢。

sendMail {
                async true
                to toAddress
                subject "New cycle initiated"
                body "<p><span style='color:#ffffe0'><strong><span style='background-color:#ff0000'>Appraisal Initiated mail notification. This is a test mail</span></strong></span></p>"
                }

这是我的代码

【问题讨论】:

  • 在您的问题中包含您用于发送电子邮件的代码。
  • @joshua 包含代码
  • 我在邮件中收到相同的 html 代码

标签: grails groovy html-email


【解决方案1】:

要使用 Grails 邮件插件以 HTML 格式发送邮件,您需要使用 html 参数而不是 body

sendMail {
    async true
    to toAddress
    subject "New cycle initiated"
    html "<p><span style='color:#ffffe0'><strong><span style='background-color:#ff0000'>Appraisal Initiated mail notification. This is a test mail</span></strong></span></p>"
}

【讨论】:

  • 谢谢doelleri..它的工作..还有一件事..我怎样才能把这个html代码分成多行?
  • 我不确定你所说的多行是什么意思。您可以将其放在模板中并使用html g.render(template: 'template.gsp')。我强烈建议您查看Grails mail plugin docs
【解决方案2】:

您可以创建一个 GSP 文件并在 sendMail 中调用它,如下所示。

'grails-app/components/mail.gsp' 中的文件

sendMail { async true
           to toAddress
           subject "blablabla"
           body(view:"/components/mail", model:[data:data])}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    • 2020-05-09
    • 2016-02-23
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多