typesafehub/play-plugins — pull request #131 by mkurz (2014-10-20 22:28:25+00:00)
Title: Mailer Bugfix: Correctly set charset BEFORE setting the html/text body

Running following code:

MailerAPI mail = play.Play.application().plugin(MailerPlugin.class).email();
mail.setSubject("Testing Charset");
mail.setRecipient("recipient@email.com");
mail.setFrom("noreply@email.com");
mail.send("Test");

sends out an e-mail with the wrong charset `us-ascii` instead of `utf-8`:

Content-Type: text/plain; charset=us-ascii

That's because right now `setCharset` is called **after** the text/html body was set. That's wrong.
Looking at the [API Documentation for `setCharset`](http://commons.apache.org/proper/commons-email/apidocs/org/apache/commons/mail/Email.html#setCharset(java.lang.String)) it says

... Please note that you should set the charset before adding the message content.

Running the above code with my fix it correctly sends out an e-mail with the correct charset:

Content-Type: text/plain; charset=UTF-8

Someone else also [already experienced this bug](https://github.com/typesafehub/play-plugins/issues/33#issuecomment-36029130).