柒八九

路漫漫其修远兮,吾将上下而求索。。。

导航

【亲测解决】javamail邮件主题支持中文,邮件内容中文乱码

使用 MimeMessageHelper 配置邮件信息,实例化时指定UTF-8编码,如下所示:

JavaMailSenderImpl javaMailSenderImpl = this.createJavaMailSenderImpl();

MimeMessage mimeMessage = javaMailSenderImpl.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8"); // 设置编码为UTF-8 String from = this.emailConfig.getFromName() + " <" + this.emailConfig.getUsername() + ">"; helper.setTo(this.to); helper.setFrom(new InternetAddress(from)); helper.setSentDate(new Date()); helper.setSubject(this.subject); helper.setText(this.content, true); helper.setReplyTo(this.emailConfig.getReplyToEmail()); helper.addAttachment(attachmentList); helper.setCc(ccAddressList);

  

 

posted on 2021-10-28 16:30  seven_7789  阅读(581)  评论(0编辑  收藏  举报