user2277149
user2277149

Reputation: 65

Properly set encoding to UTF-8, even then email come up with ? and �

I am using javax.mail API for sending email to my Outlook. There are chinese and french characters in my Body. I am properly setting body as

MimeMessage.setText(body, "UTF-8");

Also in the email I am checking the Headers. They are properly coming as : Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable

The funny thing is that from the Other Machine, the email is coming up fine, but when I try it from my desktop, It doesn't encode properly.

I am also checking logs by printing the body. They are properly coming up in chinese and french. Help needed ? Does it is anything to do with Sendmail??

Upvotes: 3

Views: 4968

Answers (1)

Joop Eggen
Joop Eggen

Reputation: 109547

Should have worked; you only forgot to do the subject too. Especially as you checked the header. Encoding calls:

MimeMessage message = new MimeMessage(session);
message.setSubject(subject, "UTF-8");
message.setText(body, "UTF-8");
//message.setHeader("Content-Type", "text/plain; charset=UTF-8");

I think, your email settings on the desktop force the wrong encoding.


Paranoia: Check the body string, via a hard-coded u-escaped string:

message.setText("\u00e9\u00f4\u5837" + body, "UTF-8"); // éô堷

Upvotes: 2

Related Questions