grails / grails-mail

The Grails Mail Plugin
https://grails.github.io/grails-mail/
Apache License 2.0
14 stars 25 forks source link

GrailsMailException: message has no content, use text(), html() or body() methods to set content #45

Closed wiggitamoo closed 4 years ago

wiggitamoo commented 4 years ago

When running Grails in development my application is sending mail correctly. When I run grails war and deploy to Tomcat, then I get the following error:

GrailsMailException: message has no content, use text(), html() or body() methods to set content

This is how I'm using the sendMail command.

String body = groovyPageRenderer.render(template: "/dfdirHeartbeatAlert/restoreHeartbeatEmail", model: [user: user, message: heartbeatMessage])

println(body)

mailService.sendMail {
            multipart true
            bcc bccList.toArray()
            from "<email_address>"
            subject "Subject"
            html body        
}

When I print out body in development it looks correct. However printing body in production deployed on Tomcat comes back as an empty string.

Is this the intended syntax for sending html mail?

davydotcom commented 4 years ago

Using the groovyPageRenderer like this can be a bit tricky. The mail plugin provides a way to specify the template and the model directly

mailService.sendMail {
            multipart true
            bcc bccList.toArray()
            from "<email_address>"
            subject "Subject"
            html view: "/emails/hello", model: [param1: "value1", param2: "value2"]
}