Javamail changing charset of subject line

前端 未结 6 2026
旧巷少年郎
旧巷少年郎 2021-02-13 20:28

I am using Javamail (javax.mail) to send mails. I successfully adjusted contents of my mail as utf-8. However I could not set subject line as a utf-8 encoded string.

I t

6条回答
  •  生来不讨喜
    2021-02-13 21:10

    Solved.

    import static java.nio.charset.StandardCharsets.*; 
    
    byte[] bytes = subject.getBytes(ISO_8859_1);
    subject = new String(bytes, UTF_8);
    
    mail.setSubject(subject);
    

提交回复
热议问题