I have similar problem to the one described in this question: I am using the "mailto" protocol to open the default mail client from Java (I am tied to Java 5 for now, so sadly I can't use the Desktop API).
Some of the emails contain Japanese text. The strings are already being UTF-8 encoded as follows:
private void email(String to, String subject, String body)
{
String encodedSubject = URLEncoder.encode(subject, "UTF-8");
String encodedBody = URLEncoder.encode(body, "UTF-8");
String mailto = "mailto:" + to + "?subject=" + encodedSubject +
"&body=" + encodedBody;
String cmd = "cmd.exe /c start \"\" \"" + mailto + "\"";
Runtime.getRuntime().exec(cmd);
}
The Japanese characters are correctly encoded to their URL-equivalents, so "平" becomes "%E5%B9%B3", for example; however, when Outlook opens the new mail window, the three-byte character is interpreted as three distinct characters - so "%E5%B9%B3" is interpreted as "å¹³".
I am fairly convinced the problem lies with outlook, since the following HTML snippet produces the same effect (SO doesn't seem to allow mailto inside tags, so I can't provide the link directly, sorry):
<html>
<body>
<a href="mailto:[email protected]?subject=%E5%b9%B3">click me to test!</a>
</body>
</html>
In short, how can I persuade Outlook to interpret multi-byte characters correctly when they're coming from a mailto link?
EDIT: To answer Johannes' question: we have a Java app which sends email when certain actions are performed. The standard text for each email is pulled from resource bundles, and in most cases we use the JavaMail API without any problems; but in this one case, there is a requirement for the user to be able to tailor the email before sending.
If anyone can suggest a non-cmd.exe
way of producing the same effect (new mail window with subject and body prefilled) - and bearing in mind that we are tied to Java 5, so the Desktop API is sadly not an option - I would be very happy!