Outlook not processing multi-byte characters when

2019-02-20 16:39发布

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:foo@bar.com?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!

5条回答
淡お忘
2楼-- · 2019-02-20 17:04

You are not specifying any encoding, so Outlook (or whoever gives the address to Outlook) can only guess. In case of your HTMl snippet, try whether specifying the encoding (UTF-8) explicitly in the <head> changes that behavior.

As far as cmd is concerned, it can't really cope with UTF-8. It handles Unicode as UTF-16, though, albeit with problems.

When I try this here (Windows Live Mail, instead of Outlook, though), everything in the subject gets converted to the legacy codepage so having CJK there should be a problem.

However, I wonder why you are trying to mis-use cmd to let the user write a mail anyway. There are surely better alternatives out there (even though I currently don't know one because I never needed it).

查看更多
\"骚年 ilove
3楼-- · 2019-02-20 17:04

The mailto: link should use RFC2047 encoding rather than UTF. http://en.wikipedia.org/wiki/MIME

mailto:me@example.com?subject==?UTF8?B?aGVsbG8?=

http://webnet77.com/cgi-bin/helpers/base-64.pl

查看更多
Juvenile、少年°
4楼-- · 2019-02-20 17:16

I guess your Java mailer works OK but to be sure, try switching to JavaMail.

Have a look at this post. Outlook 2003 by default does not correctly recognize the character encoding of HTML mails (in many case) even though they contain the appropriate tag:

 <meta http-equiv="content-type" content="text/html; charset=UTF-8">

You can switch to Outlook 2007 and/or open the mail in editor and adjust the message properties:

  • open the message
  • Edit -> Edit message
  • Format -> Encoding -> select new encoding
  • File -> Save

Edit: Corrections after the question changed.

Edit2: Sorry hadn't read the full question.

I see you have the Java 5 constraint but if the implementation is also tied to Windows, consider using a JNI/JNA based solution (unfortunately I cannot give you links on that). I would also have a look at the OpenJDK's Desktop API implementation and extract the way from it.

Another option would be to somehow pass in the message without URLEncoding it?

Also if there is a requirement for the user to customize the message before sent, you could provide a simple editor for that within your application and still send the message via JavaMail.

You could also offer the cooperative way of preparing the message for the user, putting it onto the clipboard and open the e-mail client for the user. Then the user only needs to issue a CTRL+V to paste in the prepared text.

查看更多
乱世女痞
5楼-- · 2019-02-20 17:25

The subject is alright for me in Windows Live Mail but the display name of the recipient not. When evertything is UTF-8 encoded, Android works fine but Windows Live Mail shows some symbols in "To:" while the "Subject:" is correct. When I use UTF-16 for "To:", Windows Live Mail works now but Android still gets it as UTF-8...

查看更多
别忘想泡老子
6楼-- · 2019-02-20 17:28

You can try this:

There is an option called : Enable UTF-8 support for mailto:protocol in Outlook @

Tools > Options > Mail Format > International Options > [x] Enable UTF-8 support for mailto:protocol

Lets hope it works for you

查看更多
登录 后发表回答