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 & 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
# 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.
# 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>