Home  >  Article  >  Java  >  Java email garbled solution

Java email garbled solution

尚
Original
2019-12-21 16:20:562289browse

Java email garbled solution

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn