Javamail changing charset of subject line

前端 未结 6 2030
旧巷少年郎
旧巷少年郎 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:17

    Solved.

    mail.setSubject(MimeUtility.encodeText(subject, "utf-8", "B"));
    

    solves it and sends utf-8 encoded mail subjects. \n/

    the legal values for "encoding" are "Q" and "B"... The "Q" encoding is recommended for use when most of the characters to be encoded are in the ASCII character set; otherwise, the "B" encoding should be used.

    See http://tools.ietf.org/html/rfc2047.

提交回复
热议问题