尝试以电子邮件的形式发送HTML内容时缺少属性异常

时间:2014-06-29 05:12:32

标签: grails groovy

我正在渲染视图并尝试发送电子邮件。但是会发生以下错误:

Class
groovy.lang.MissingPropertyException
Message
No such property: content for class: grails.plugin.mail.MailMessageBuilder

代码:

def content=groovyPageRenderer.render view: '/email/mail', model: [username: u]

 if(mailService!=null){
    mailService.sendMail {
    to "mail@yahoo.com"
    from "f@fff.com"
    subject "rrr"

    html(content)
 }

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是我的代码示例,用于执行相同的操作

class FeedbackController {
    def mailService // <-- Injection of mail service from the 'mail' plugin

    def sendTestMsg() {
        mailService.sendMail {
            to "test@mail.test"
            subject "Some important topic"
            html g.render(template: "contactMailTemplate",
                    model: [remark: "Test one-two-three", yourname: "Testing bot", yourmail: "testbot@mail.test"])
        }
        render "success"
    }
}

_contactMailTemplate.gsp。这是标准的HTML,但我已经取代了&#34;&lt;&gt;&#34;签到&#34; []&#34;因为StackOverflow会使用它们并用于格式化。

[%@ page contentType="text/html" %]
[html]
[head]
    [title]Welcome Aboard[/title]
    [style type="text/css"]
    body {
        font-family: "Trebuchet MS"
    }
    [/style]
[/head]
[body]
[h2]Question from users![/h2]
[p]
    [strong]${yourname}[/strong] asked us from the [strong]${yourmail}[/strong] address
[/p]
[p]
    ${remark}
[/p]
[/body]
[/html]