使用SpringMVC+Java mail发送HTML邮件

1 添加基本依赖

JavaMail

  • mail.jar

Spring framework

  • spring-beans-3.2.0.RELEASE.jar
  • spring-context-3.2.0.RELEASE.jar
  • spring-context-support-3.2.0.RELEASE.jar
  • spring-core-3.2.0.RELEASE.jar
  • spring-expression-3.2.0.RELEASE.jar
  • spring-web-3.2.0.RELEASE.jar
  • spring-webmvc-3.2.0.RELEASE.jar

Apache Commons Logging

  • commons-logging-1.1.1.jar

2 添加xml配置到spring配置文件中


     
     
     
     
     
           
              smtp
              true
              true
          


3 发送html格式邮件

MimeMessage mimeMsg = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMsg, false, "utf-8");
mimeMsg.setContent(htmlContent, "text/html");
helper.setTo(recipientAddress);
helper.setSubject(subject);
helper.setFrom(Constant.SITE_EMAIL);
mailSender.send(mimeMsg);

你可能感兴趣的:(使用SpringMVC+Java mail发送HTML邮件)