3

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??

1
  • Is the problematic Outlook connecting to a Microsoft Exchange server by any chance?
    – tripleee
    Dec 13, 2013 at 9:49

1 Answer 1

2

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"); // éô堷
2
  • 1
    My subject is Normal Ascii. More Over I think there is no need to do message.setHeader("Content-Type", "text/plain; charset=UTF-8"); As Headers are coming properly fine... Content-type: text/plain; charset="UTF-8" Content-transfer-encoding: quoted-printable Dec 13, 2013 at 8:48
  • Yes setHeader not needed; copied from my list of error sources. Though the subject you could try; maybe Outlook looks only at the subject encoding? (Improbable.) One may only set the encoding to UTF-8 for the outgoing email in Outlook. Maybe your mail server?
    – Joop Eggen
    Dec 13, 2013 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.