Illep
Illep

Reputation: 16851

Sending mail No such property g

I am getting this error message:

No such property: g for class: grails.plugin.mail.MailMessageBuilder

The code is:

mailService.sendMail {
                to "[email protected]" 
                from "[email protected]" 
                subject "Welcdome to d "
                body "jjj"
                html g.render(template: "/email/mailll",
            model: [remark: "OLAA PEOPLE!", yourname: user.firstName, yourmail: user.username])
            }

Upvotes: 0

Views: 1035

Answers (3)

Ian Roberts
Ian Roberts

Reputation: 122394

You shouldn't use html and body together, just use one or the other. The body call can take view and model parameters to do the template rendering itself, you don't need to use g.render (and you can't, if you're in a service rather than a controller).

mailService.sendMail {
    to "[email protected]" 
    from "[email protected]" 
    subject "Welcdome to d "
    body(view:"/email/_mailll", model: [remark: "OLAA PEOPLE!",
                yourname: user.firstName, yourmail: user.username])
}

Note that the view parameter doesn't do the underscore transformation on template names, so you have to include the underscore yourself if the GSP you want to render includes one.

Upvotes: 3

injecteer
injecteer

Reputation: 20699

This code is valid only if called in a Controller or TagLib. The g-Taglib object is not available in any other Grails artefacts, like Service.

If you want to render the email-body from a Service, you must use groovy's SimpleTemplateEngine

Upvotes: 2

MKB
MKB

Reputation: 7619

From your last question: You are in service and in service taglibs are not accessible so for sending templates you need groovyPageRenderer like Missing property exception when trying to send HTML content in the form of an email in your question.

Upvotes: 1

Related Questions