Java application email libraries include: Java mail native, Spring, and apache email (and others). Lots of articles say apache email API is more intuitive, but others say if you are already using a Java/Spring application, then to go ahead and use the Spring one. I decided to try the Spring Boot one first, since we have a Java/Spring application.
The Spring boot library satisfied the three criteria below, and seems to work great on my local environment:
- the ability to send simple text email
- the ability to send HTML email (support for HTML emails already had the Thymeleaf HTML templating library provided with Spring Boot)
- the ability to attach a file(s) to the email
Environment:
Windows 7
Oracle Java 1.8.0_66
Spring Boot 1.3.1.RELEASE
Sprint Boot 1.3.1.RELEASE spring-boot-starter-thymeleaf
The example below supports criteria number 2 to send HTML emails using Thymeleaf email templates. I've also included unescaped HTML, passing multiple variables to HTML template, and inline image in the example below as well.