Java Mail API - Encoding problems

前端 未结 9 1309
野趣味
野趣味 2020-12-31 11:14

I\'m using Java Mail API and I\'m trying to send an email through Gmail\'s SMTP. How my program works: java.util.Scanner class is used to get user input - I\'m asking user f

9条回答
  •  生来不讨喜
    2020-12-31 11:48

        MimeMessage message = new MimeMessage(session);
        message.setSubject(subject, "UTF-8");
        message.setText(body, "UTF-8");
    

    So one has to set the character encoding for both, body and subject.


    Addendum because of comment of @bartac

    For the corresponding MimeBodyPart do a setHeader("Content-Type", "text/plain; charset=UTF-8").

提交回复
热议问题