发送HTML邮件内容显示不对
@Override
public void sendHtmlMail(String to, String subject, String content) {
MimeMessage mimeMessage = sender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,true);
helper.setFrom(from);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(content,true);
sender.send(mimeMessage);
} catch (MessagingException e) {
e.printStackTrace();
}
}
@Test
public void sendHtmlMail(){
String content = "<html>\n"+
"<body>\n"+
"<h3> hello world 这是一封HTML邮件!</h3>\n"+
"</body>\n"+
"</html>";
mailservice.sendHtmlMail("chen1765547530@163.com", "这是一封HTML邮件", content);
}
代码如上:
明明发送的是HTML邮件,内容竟然变成了这样
<html> <body> <h3> hello world 这是一封HTML邮件!</h3> </body> </html>