Instructions for sending Chinese attachment title garbled in JavaMail

Source: Internet
Author: User
Previously in the CSDN posted a post that may be a bug, would like to directly reply to that post, perhaps due to Csdn's revision? I can't reply to that post now, I can only make a note here.
received a reply from the Sun engineer, gave me a corresponding FAQ link, I am sorry I did not go to the query FAQ:-)
Http://java.sun.com/products/javamail/FAQ.html#encodefilename
The reason is that in the corresponding specification of MIME (RFC2047, etc.), the attachment title must be Us-ascii character, so you need to encode us-ascii characters in the attachment of the Chinese title, there are two ways to encode: B (BASE64), Q (quoted-printable , these methods are already encapsulated in mimeutility, so use the method when sending attachments:
Setfilename (Mimeutility.encodetext (FileName, "GBK"));
But now the mail system is not very consistent here, so there may be a number of individual mail system is garbled, you can choose according to the appropriate encoding method.
As previously mentioned, take iso8859-1 bytes directly: Setfilename (New String (File.getname (). GetBytes (), "iso8859-1"));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.