创建文本/ html发送

时间:2018-10-23 08:48:10

标签: java javamail mime

当您发送带有html的电子邮件时,该电子邮件中包含以下内容:

<html> = 09
= 09 = 09 <! - NAME: 1 COLUMN ->
= 09 = 09 <! - [if gte mso 15]>
= 09 = 09 <xml>
= 09 = 09 = 09 <or: OfficeDocumentSettings>
= 09 = 09 = 09 </ o: OfficeDocumentSettings>
= 09 = 09 </ xml>
= 09 = 09 <! [Endif] ->
= 09 = 09 <meta charset = 3D "UTF-8">
        <meta http-equiv = 3D "X-UA-Compatible" content = 3D "IE = 3Dedge">
        <meta name = 3D "viewport" content = 3D "width = 3Ddevice-width, initial-sc =
ale = 3D1 ">

= 09 = 09和= 3D导致电子邮件正文无法正常工作。 导致我在html中的某些按钮中的参数不起作用

MimeMessage mail = mailSender.createMimeMessage();
MimeMultipart multi = new MimeMultipart();
MimeBodyPart textPart = new MimeBodyPart();
MimeBodyPart textHtml = new MimeBodyPart();

if (html.isEmpty()) {
  textPart.setText(text, "utf-8");
  multi.addBodyPart(textPart);
} else {                     
  textHtml.setContent(MimeUtility.decodeText(html), "text/html");
  textHtml.setHeader("Content-type", "text/HTML");

  multi.addBodyPart(textHtml);
}

mail.setContent(multi);
mail.setSubject(subject);
mail.setFrom(from);
mail.setRecipients(Message.RecipientType.TO, to[0].toString());
mail.saveChanges();
this.mailSender.send(mail);

请帮助!

0 个答案:

没有答案