Java Mail API - Encoding problems

前端 未结 9 1379
野趣味
野趣味 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:26

    The following worked for me:

    MimeMessage message = ...
    message.setSubject(subject, "UTF-8");
    message.setContent(body, "text/plain; charset=UTF-8");
    

    Where subject and body are regular String objects with no special treatment (code and user interface use UTF-8).

提交回复
热议问题