MailService { public void sendHtmlMail(String toMail,String subject,String content) { MimeMessage createMimeMessage = sender.createMimeMessage(); try { MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(createMimeMessage,true); mimeMessageHelper.setFrom(formMail); mimeMessageHelper.setTo(toMail); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setText(content, true); sender.send(createMimeMessage); logger.info("发送给"+toMail+"html邮件已经发送。 subject："+subject); } catch (MessagingException e) { logger.info("发送给"+toMail+"html send mail error subject："+subject); e.printStackTrace(); } }  void sendSimpleMail(String toMail,String subject,String content); void sendHtmlMail(String toMail,String subject,String content); void sendInlineResourceMail(String toMail,String subject,String content,List<InlineResource> resourceist); void sendInlineResourceMailForGroupSending(String[] toMail,String subject,String content,List<InlineResource> resourceist); void sendAttachmentsMail(String toMail,String subject,String content,String filePath);  }
@Test public void sendHtmlMail() { String html= "<!DOCTYPE html>\r\n" + "<html>\r\n" + "<head>\r\n" + "<meta charset=\"UTF-8\">\r\n" + "<title>Insert title here</title>\r\n" + "</head>\r\n" + "<body>\r\n" + " <font color=\"red\">发送html</font>\r\n" + "</body>\r\n" + "</html>"; mailService.sendHtmlMail("******@qq.com", "这是一个测试邮件", html); }