javainternationalizationjakarta-mailiso-8859-2

Java mail charset ISO-8859-2 not working


I am having problem with Java Mail API.

I can successfully send mail, but some special characters (from ISO-8859-2 languages like czech, slovak) are not shown in mail. They are damaged even in IDE output.

What am I doing wrong?

Message msg = new MimeMessage(session);
msg.setContent(message, "text/plain; charset=iso-8859-2")

Solution

  • I found solution, using multipart. here is code :

    MimeMessage msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(from));
    MimeMultipart multipart = new MimeMultipart();
    msg.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
    MimeBodyPart tmpBp = new MimeBodyPart();
    tmpBp.setContent(message,"text/plain; charset=utf-8");
    multipart.addBodyPart(tmpBp);
    msg.setContent(multipart);
    Transport.send(msg);