Sending emails using JavaMail
Now, let's implement the sending email feature using JavaMail. We will also use FreeMarker as the template engine to create the body of the email message.
First of all, let's add the following dependencies to pom.xml
:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId> </dependency> ... <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> </dependency>
The spring-boot-starter-mail
starter provides interfaces, such as JavaMailSender
, to make the implementation of sending email relatively easy, as you will see in this section. With the presence of the FreeMaker library, Spring Boot will automatically create an instance of freemarker.template.Configuration
. By default, the template loader path is classpath:/templates/
, which has been used to store Thymeleaf view templates. It is better that we separate...