windows 使用 mailto 时 Outlook 不处理多字节字符:
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/974558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Outlook not processing multi-byte characters when using mailto:
提问by Ashley Mercer
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).
我有与此问题中描述的问题类似的问题:我正在使用“mailto”协议从 Java 打开默认邮件客户端(我现在绑定到 Java 5,很遗憾我不能使用桌面 API)。
Some of the emails contain Japanese text. The strings are already being UTF-8 encoded as follows:
一些电子邮件包含日语文本。字符串已经被 UTF-8 编码如下:
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 "?13".
日语字符被正确编码为它们的 URL 等价物,例如,“ƽ”变成了“%E5%B9%B3”;但是,当 Outlook 打开新邮件窗口时,三字节字符被解释为三个不同的字符 - 因此“%E5%B9%B3”被解释为“?13”。
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):
我相当确信问题出在 Outlook 上,因为以下 HTML 代码段产生了相同的效果(所以似乎不允许在标签内使用 mailto,所以我无法直接提供链接,抱歉):
<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?
简而言之,当它们来自 mailto 链接时,我如何说服 Outlook 正确解释多字节字符?
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.
编辑:回答约翰内斯的问题:我们有一个 Java 应用程序,它在执行某些操作时发送电子邮件。每封电子邮件的标准文本都是从资源包中提取的,在大多数情况下,我们使用 JavaMail API 没有任何问题;但在这种情况下,用户需要能够在发送之前定制电子邮件。
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!
如果有人可以提出一种cmd.exe
产生相同效果的非方式(带有主题和正文预填充的新邮件窗口) - 并记住我们与 Java 5 相关联,所以遗憾的是桌面 API 不是一个选项 - 我会非常快乐的!
回答by Salvin Francis
You can try this:
你可以试试这个:
There is an option called : Enable UTF-8 support for mailto:protocol in Outlook @
有一个选项叫做:在 Outlook @ 中为 mailto:protocol 启用 UTF-8 支持
Tools > Options > Mail Format > International Options > [x] Enable UTF-8 support for mailto:protocol
工具 > 选项 > 邮件格式 > 国际选项 > [x] 为 mailto:protocol 启用 UTF-8 支持
Lets hope it works for you
希望它对你有用
回答by TimTim
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...
Windows Live Mail 中的主题对我来说没问题,但收件人的显示名称不行。当所有内容都采用 UTF-8 编码时,Android 工作正常,但 Windows Live Mail 会在“收件人:”中显示一些符号,而“主题:”是正确的。当我将 UTF-16 用于“收件人:”时,Windows Live Mail 现在可以工作,但 Android 仍然将其作为 UTF-8 获取...
回答by tripleee
The mailto: link should use RFC2047 encoding rather than UTF. http://en.wikipedia.org/wiki/MIME
mailto: 链接应该使用 RFC2047 编码而不是 UTF。http://en.wikipedia.org/wiki/MIME
mailto:[email protected]?subject==?UTF8?B?aGVsbG8?=
mailto:[email protected]?subject==?UTF8?B?aGVsbG8?=
回答by Joey
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.
您没有指定任何编码,因此 Outlook(或向 Outlook 提供地址的任何人)只能猜测。如果是您的 HTMl 片段,请尝试是否在<head>
更改行为时明确指定编码 (UTF-8) 。
As far as cmd is concerned, it can't really cope with UTF-8. It handles Unicode as UTF-16, though, albeit with problems.
就cmd而言,它并不能真正应付UTF-8。尽管存在问题,但它将 Unicode 作为 UTF-16 处理。
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.
当我在这里尝试这个(Windows Live Mail,而不是 Outlook)时,主题中的所有内容都会转换为旧代码页,因此使用 CJK 应该会出现问题。
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).
但是,我想知道您为什么要误用cmd
让用户无论如何都写邮件。肯定有更好的选择(即使我目前不知道一个,因为我从不需要它)。
回答by akarnokd
I guess your Java mailer works OK but to be sure, try switching to JavaMail.
我猜你的 Java 邮件程序工作正常,但可以肯定的是,尝试切换到JavaMail。
Have a look at thispost. Outlook 2003 by default does not correctly recognize the character encoding of HTML mails (in many case) even though they contain the appropriate tag:
看看这个帖子。默认情况下,Outlook 2003 无法正确识别 HTML 邮件的字符编码(在许多情况下),即使它们包含适当的标记:
<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:
您可以切换到 Outlook 2007 和/或在编辑器中打开邮件并调整邮件属性:
- 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.
Edit2:抱歉没有阅读完整的问题。
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.
我看到您有 Java 5 约束,但如果实现也与 Windows 相关联,请考虑使用基于 JNI/JNA 的解决方案(不幸的是,我无法为您提供相关链接)。我还将查看 OpenJDK 的桌面 API 实现并从中提取方法。
Another option would be to somehow pass in the message without URLEncoding it?
另一种选择是以某种方式在没有 URLEncoding 的情况下传递消息?
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.
此外,如果用户需要在发送前自定义消息,您可以在应用程序中为此提供一个简单的编辑器,并且仍然通过 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.
您还可以提供为用户准备消息的合作方式,将其放入剪贴板并为用户打开电子邮件客户端。然后用户只需要发出 CTRL+V 来粘贴准备好的文本。