Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send a multi-part email with text/plain and text/html parts with Grails?

Tags:

email

mime

grails

I've looked through the code and documentation for the Grails Mail plugin (version 0.9) and it doesn't have the support I'm looking for. You can only set a single body and then provide a mime attachment that points to a static file. I need to actual pass a model into a GSP and have it render both the HTML and plain text versions and then have those both available in the message. This will allow non-HTML-based e-mail clients to display the text/plain part and clients that support HTML to display the text/html part.

Has anybody done this with Grails? Is there an easy way to do it, or do I have to modify the mail plugin or just go to the Java Mail library directly?

like image 532
Javid Jamae Avatar asked Sep 14 '10 02:09

Javid Jamae


1 Answers

Since version 1.0 the mail plugin natively supports multipart alternative content as described in http://jira.grails.org/browse/GPMAIL-37

mailService.sendMail {
    multipart true
    to <recipient>
    subject <subject string>
    text 'my plain text'
    html '<html><body>my html text</body></html>'
}
like image 184
martin Avatar answered Sep 22 '22 17:09

martin