JavaMail the solution of the topic garbled in sending mail

Source: Internet
Author: User
Tags base64 mail
Send a message | To solve many friends have used JavaMail to send mail, in the message body garbled easily resolved. But the message theme garbled no matter how the transcoding always shows a pile of garbled. What should I do with it?

The message subject in JavaMail needs to be BASE64 encoded, in the form of:
=? GB2312? b?xpq1xmpcwuvs0b6t1tjww6osx+u+ob/stcfcvkossqlq3rjew9zc66oh?=
Therefore, the direct use of Msg.setsubject ("Chinese theme"), or Msg.setsubject ("Chinese theme". GetBytes ("8859_1"), "GB2312") will appear garbled. You need to encode the byte of the subject string into the BASE64 format before you set the message subject, and add the encoding header, as shown in the sample code:


Sun.misc.BASE64Encoder enc = new Sun.misc.BASE64Encoder (); Msg.setsubject ("=? GB2312? B? " +enc.encode (Subject.getbytes ()) + "? =");


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.