java solution for sending garbled emails:
//设置邮件主题 message.setSubject(MimeUtility.encodeText(mail_subject,MimeUtility.mimeCharset("gb2312"), null)); message.setContent(sendmessage, "text/html;charset=gbk"); // 设置邮件格式 message.setSentDate(new Date()); // 设置邮件发送日期 //设置邮件发件人名称 Address address = new InternetAddress(usernames, MimeUtility.encodeText(personalName,MimeUtility.mimeCharset("gb2312"), null));
When a piece of Text or HTML is sent via email, the sent content first passes through a specified character The encoding is converted into a "byte string", and then the "byte string" is converted through a specified transfer encoding (Content-Transfer-Encoding) to obtain another string of "byte strings".
The title of the email uses a shorter format to mark "Character Encoding" and "Transfer Encoding".
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of Java email garbled solution. For more information, please follow other related articles on the PHP Chinese website!