Search code examples
emailgrailsmime

How can I send a multi-part email with text/plain and text/html parts with 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?


Solution

  • 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>'
    }