Java mail encoding non english characters

后端 未结 3 365
日久生厌
日久生厌 2020-12-16 22:27

Using the code below i can send an email written in non-english and although the subject appears correctly the body appears as gibberish.
Any ideas?
Thank you

<
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 22:51

    Instead of

    msg.setContent(message, "text/plain");
    

    I would write

    Multipart mp = new MimeMultipart();
    MimeBodyPart mbp = new MimeBodyPart();
    mbp.setContent(message, "text/plain; charset=ISO-8859-7");
    mp.addBodyPart(mbp);
    
    msg.setContent(mp);
    

    I guessed ISO-8859-7 from your name because this charset is for Greek, but maybe you can choose it more properly. Or maybe also UTF-8 works for your case.

提交回复
热议问题