Sending mail but displaying the uncode in subject filed...some wht urgent

Hi every one

and Thanx to every one...for giving their precious help for every one

Here i want to explain a small problem in java mail with unicode

Here it is ....

Iam sending a mail with some chinese characters in the subject field..internally these chineese characters are converting in to html unicode format like(主).

the code goes like this :

MimeMessage message =new MimeMesage();

String subject=主的电

message.setSubject(subject,"utf-8");

......remaining are setted properly i mean from ,to using InternetAddress

Multipart multipart = new MimeMultipart();

BodyPart messageBodyPart = new MimeBodyPart();

messageBodyPart.setContent(content, "text/html");

multipart.addBodyPart(messageBodyPart);

message.setContent(multipart);

Transport.send(message);

Now

It is sending mail to the receipents but in at the receiver side the mail's subject field contains unicode in stead of chinese characters....if i open and seen the viewsource from the page it is adding an extra &amp instead of &..i think it is not filtering th unicode ....here iam sending the mail to gmail...

I didn't understand where iam doing the mistake please give some idea how to do this .....and let know where iam doing worng programming ....

it s very urgent for me ...please

Thanx in advance ......

Srikanth

[1450 byte] By [srikanth_bsba] at [2007-11-27 2:11:24]
# 1

sorry here in the above post the unicode string converted to chinese char but the actual string it is displaying is like 主

please i requesting you replace the &amp with &...beacuse here it is coverting to chinese so that's why iam specifying &amp instead of &

Thank you

srikanth_bsba at 2007-7-12 2:04:30 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
If you're setting the string as a literal string constant in your Java sourcecode, you should use the Unicode escape sequence, i.e., "\u####",not the html escape sequence.
bshannona at 2007-7-12 2:04:30 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

Hi

Thanx alot for your reply

According to your reply i converted that string literal to unicode but the chinese characters are dispalying in the for of unicode but not in chinese...at receiving side....

Please can you alobarate your post with any exmaple....

Thank you

srikanth

srikanth_bsba at 2007-7-12 2:04:30 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

I can't give you an example because I don't know Chinese, sorry.

If you have the correct Unicode values for the Chinese characters,

and the receiving mailer isn't displaying them properly, then that's

either a bug in the receiving mailer or the receiving mailer doesn't

understand the charset (e.g., "utf-8") that you're using. You might

try using a Chinese-specific charset.

Another way to debug this problem is to send a message using

a mailer that causes the message to be displayed as you want,

and then work backwards to do what you need in your code to

replicate what the other mailer does. Use the "view message

source" function in the receiving mailer to examine the message

that displays properly and compare it with the message that doesn't

display properly.

bshannona at 2007-7-12 2:04:30 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5

hi bshannon

i solved this problem .....i will explain what did here

here iam getting the string literal from the DB as NCR formated string

so i converted that string to unicode string ...(Ex: "𵭻")

This method will converts the NCR fomated string to UnicodeString:

public static String NCR2UnicodeString(String str)

{

StringBuffer ostr = new StringBuffer();

int i1=0;

int i2=0;

while(i2<str.length())

{

i1 = str.indexOf("&#",i2);

if (i1 == -1 ) {

ostr.append(str.substring(i2, str.length()));

break ;

}

ostr.append(str.substring(i2, i1));

i2 = str.indexOf(";", i1);

if (i2 == -1 ) {

ostr.append(str.substring(i1, str.length()));

break ;

}

String tok = str.substring(i1+2, i2);

try {

int radix = 10 ;

if (tok.trim().charAt(0) == 'x') {

radix = 16 ;

tok = tok.substring(1,tok.length());

}

ostr.append((char) Integer.parseInt(tok, radix));

} catch (NumberFormatException exp) {

ostr.append('?') ;

}

i2++ ;

}

return new String(ostr) ;

}

from this method i will get a string the unicode ...and iam setting this string to subject

MimeMessage message =new MimeMessage();

message.setSubject("string from the above method","utf-8");

and remaing setting all are doing here

finally

Transport.send(message);

I hope you are also expained the same thing ...

and a lot thanx to you to solve my urgent problem...

Thanx

Srikanth>

srikanth_bsba at 2007-7-12 2:04:30 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...