简体   繁体   English

MimeMessage内容类型java

[英]MimeMessage Content Type java

StringBuffer messageText = new StringBuffer();
messageText.append("<style type=\"text/css\">" +
                    "#message p {some style }" +
                    "</style>");
messageText.append("<p>");
(L1)messageText.append("abc’s email level…def");            
messageText.append("</p>");
message.setContent(messageText.toString(), "text/html;");
Transport.send(message);

When i ran the code found two different variations of the output. 当我运行代码时,发现输出有两个不同的变化。

I first typed this message abc's email level…def in the microsoft word, then copied this to the eclipse editor. 我首先在Microsoft Word中键入此消息abc's email level…def ,然后将其复制到eclipse编辑器。 when i run the program message that was in email is something different like this abc?s email level?def 当我运行电子邮件中的程序消息时,与此abc?s email level?def

But when i type this message abc's email level…def in the eclipse editor then I am seeing the same message in email. 但是,当我在Eclipse编辑器中键入此消息abc's email level…def ,我在电子邮件中看到了相同的消息。

What should I change in the code to receive the same message in the email even if i copy something from microsoft word... 即使我从Microsoft Word复制某些内容,我也应该更改代码中的哪些内容以在电子邮件中接收相同的消息...

This is almost certainly an encoding problem between your editors (MS-Word and Eclipse, in this case) and your program. 几乎可以肯定,这是您的编辑器(在本例中为MS-Word和Eclipse)与程序之间的编码问题。 You'll want to verify that the content you are copying and pasting from MS-Word to eclipse is UTF-8 on both sides, I suspect that it is not. 您将要验证从MS-Word复制并粘贴到eclipse的内容的两面都是UTF-8,我怀疑不是。

The commenter is right that this problem is problem microsoft's smart quotes, which don't generally paste correctly, you can write a regular expression to replace them ; 评论者说的很对,这个问题是微软的智能引号,通常不能正确粘贴,您可以编写一个正则表达式来替换它们 but this is a specific work around for those particular characters, and will not handle a generic case. 但这是针对那些特定字符的特定解决方法,并且不会处理一般情况。

The root cause is almost certainly an encoding mismatch between what you are pasting from MS-Word, and what your java code expects. 根本原因几乎可以肯定是您从MS-Word粘贴的内容与Java代码期望的内容之间的编码不匹配。 You can check your eclipse settings to verify you are using UTF-8 as a default, check your word settings to verify the source document is also UTF-8. 您可以检查日食设置以确认您使用的是UTF-8作为默认设置,可以检查单词设置以确认源文档也是UTF-8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM