Forum Stats

  • 3,837,399 Users
  • 2,262,255 Discussions
  • 7,900,269 Comments

Discussions

Mail with Unicode Characters (Cyrillic) in Subject

843810
843810 Member Posts: 46,938
edited Jul 22, 2011 3:22PM in Java Desktop Applications
Hello,

how can we send an email with Unicode characters (more specifically, Cyrillic) in the Subject line, using java.awt.Desktop?
Here is the small piece of code:
...
if (!Desktop.isDesktopSupported())
    return false;
Desktop desktop = Desktop.getDesktop();
if (!desktop.isSupported(Desktop.Action.MAIL)) 		    
    return false;

String sURI = "[email protected]?SUBJECT=\u041f\u043e\u0437\u0434\u0440\u0430\u0432";

URI uri = new URI("mailto", sURI, null);
desktop.mail(uri);
...
MS Outlook will pop open but will show question marks in the subject line (???????).

When I tried to encode the Unicode string with URLEncoder (or with my own base64 encoder), the subject line shows that string just as it is (encoded).
String sURI = "[email protected]?SUBJECT=" + URLEncoder.encode("\u041f\u043e\u0437\u0434\u0440\u0430\u0432", "utf-8");
Can anything be done here? The similar question is applicable also for body of the email.

Regards

Comments

  • 843810
    843810 Member Posts: 46,938
    In the meantime, I had to solve my problem one way or another, and the only thing that came up to my mind was to use JavaMail API.
    It is not quite what I was hoping for, because it doesn't provide opening of default e-mail client on local machine, but at least it can send e-mail with Unicode characters in the subjects line, recipient addresses, etc.

    Make a new message using JavaMail and then set it's properties in a fairly simple manner, like this:
    message.setSubject( MimeUtility.encodeText("+ ... some Unicode text with Cyrillic symbols ... +", "UTF-8", "B") );
    I'd still like to see if there are any suggestions on how to do the similar thing with java.awt.Desktop.

    Regards,
    PS
  • 877458
    877458 Member Posts: 31
    I exactly followed your code, however, the subject still shows unicode, not the Chinese I expected.

    message.setSubject(MimeUtility.encodeText("亲爱的用户", "UTF-8", "B"));

    Anything suggestions?
  • DrClap
    DrClap Member Posts: 25,479
    My suggestion would be
    message.setSubject("亲爱的用户");
  • 877458
    877458 Member Posts: 31
    I tried that before and it did not work. The subject still shows unicode, not Chinese.

    Any other suggestions?
  • DrClap
    DrClap Member Posts: 25,479
    My suggestion would be to have posted the question in the JavaMail forum in the first place. However now my suggestion is to go over there and search for answers.
  • 877458
    877458 Member Posts: 31
    Tried and could not find any answers. If you find one, please let me know. Thanks,
This discussion has been closed.