In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Java email garbled complete solution, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
The solution to the garbled code of java sending email:
/ / set email subject message.setSubject (MimeUtility.encodeText (mail_subject,MimeUtility.mimeCharset ("gb2312"), null); message.setContent (sendmessage, "text/html;charset=gbk"); / / format email message.setSentDate (new Date ()); / / set email delivery date / / set email sender name Address address = new InternetAddress (usernames, MimeUtility.encodeText (personalName,MimeUtility.mimeCharset ("gb2312"), null))
When a Text or HTML is sent by e-mail, the sent content is first converted into a "byte string" by a specified character encoding, and then the "byte string" is converted to another "byte string" by a specified transmission code (Content-Transfer-Encoding).
The title of the message is marked with "character encoding" and "transmission coding" in a shorter format.
Expand content
1. Set the encoding format when constructing MimeMessageHelper
@ Resourceprivate JavaMailSender javaMailSender;@Testpublic void mimeMailTest () throws MessagingException {String email = "xxx-xxx@163.com"; String mailCode = 123456789 new MimeMessageHelper / create a multi-purpose mail message object MimeMessage mailMessage = javaMailSender.createMimeMessage (); / / create a mail message assistant (parameter 2: set to true, indicating that hyperlinks, attachments can be sent) MimeMessageHelper messageHelper = new MimeMessageHelper (mailMessage, true, "UTF-8"); messageHelper.setTo ("xxx-xxx@163.com") MessageHelper.setFrom ("xxx-xxx@163.com"); messageHelper.setSubject ("Registration reminder"); String text = "register successfully, click activate"; / / Parameter 2 indicates whether to send it in html format. If not, plain text messageHelper.setText (text, true); javaMailSender.send (mailMessage);} will be sent.
two。 The encoding is not set when constructing MimeMessageHelper, but when using the setContent () method of MimeMessage
@ Testpublic void mimeMailTest2 () throws MessagingException {String email = "xxx-xxx@163.com"; String mailCode = 123456789 / create a multi-purpose mail message object MimeMessage mailMessage = javaMailSender.createMimeMessage (); / / create a mail message assistant MimeMessageHelper messageHelper = new MimeMessageHelper (mailMessage); messageHelper.setTo ("xxx-xxx@163.com"); messageHelper.setFrom ("xxx-xxx@163.com"); messageHelper.setSubject ("Registration reminder 2"); String text = "Registration successful 2, click activate" / / Parameter 2: send mailMessage.setContent (text, "text/html;charset=UTF-8") in html format; javaMailSender.send (mailMessage);}
After reading the above, have you mastered the complete solution to the garbled code of java email? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.