JavaMail sending mail attachment from string - encoding UTF-8

前端 未结 8 2055
面向向阳花
面向向阳花 2021-02-03 22:34

My application has to send a textfile, which it first has to generate as a String. The text contains non-ASCII symbols, so i would like it to be UTF-8. I\'ve tried a lot of vari

8条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-03 23:23

    One more possibility:

    String attachment = "älytöntä";
    MimeBodyPart part = new MimeBodyPart();
    part.setText(attachment, "UTF-8");
    part.setDisposition("attachment");
    part.setFileName("attachment.txt");
    part.setHeader("Content-Transfer-Encoding", "base64");
    part.setHeader("Content-type", "text/plain; charset=utf-8");
    

提交回复
热议问题