开发者

Swedish text(vår, än, tall).try to send a mail .But while getting mail Question Mark(?) is observed in place accent character in Linux Env

I read the template which contains the Swedish text(vår, än, tall) . then I try to send a mail . But while getting mail Question Mark(?) is observed in place of special or accent character . In Windows it work fine but in Linux it’s not support. I have used content type as :

text/html; charset=ISO-8859-1  (Windows work fine but in Linux it does not support)
text/html;charset=utf-8               (Windows work fine but in Linux it does not support)
text/x-vcard; charset=utf-8
text/plain; charset=ISO-8859-1; format=flowed

I set content Type as CONTENT_TYPE = "text/html;charset=utf-8"; Is there any solution ,to get proper mail.

private final static String CONTENT_TYPE = "text/html; charset=ISO-8859-1";
Message msg = new MimeMessage(session);
msg.setContent(message, CONTENT_TYPE);
System.setproperty("utf开发者_开发技巧8");

I am getting ? in place of accent characters in Linux Env.


If you want your String to be encoded correctly, you should use one of the methods:

MimeMessage.setText(String text, String charset) 
MimeMessage.setText(String text, String charset, String subtype)

which allow you to specify the charset of your text (i.e. "utf-8") and additionally the subtype (e.g. "plain", as in "text/plain")


Actually problem was while read the text.b/c inputstreamreader was reading the file with UTF-8 character set which provided by linux as default.that's why question marks are observed in place of accent characters. And in windows inputstreamreader use characterset as MS-1252 which also support swedish text. that's why mail was coming proper in windows.So i come to know that always find the root cause problem was not to send a mail .problem was in reading the file.

For future reference, Analysis of the issue is as follows:

Root Cause: Input stream reader of java takes the default character set based on operating system if not specified explicitly. While trying to read the file using input stream reader of java: • For UNIX system: Default character set is “UTF-8” which do not support Swedish (Latin) characters. • For Windows system: Default character set is “MS-1252” which supports Latin characters.

Solution: Set the correct character set while initializing the input stream reader in java for reading the file from file system. This will avoid defaulting of character set based on operating system.

Use constructor (suggested): InputStreamReader(InputStream in, String charsetName)

Generally used constructor (avoid for supporting different charsets): InputStreamReader(InputStream in)

Sample code: new InputStreamReader(bfInputStream, CHARACTER_SET); where CHARACTER_SET = “ISO-8859-1”

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜