第一步: 导包
<!-- 发邮件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
第二步:
package com.xiaolvmao.blog.common; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.core.io.FileSystemResource; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Component; import java.io.File; import java.time.LocalDateTime; /** * @author zhangxc * @date 2019-07-23 09:29 * @email */ @Component public class SendEmailTool { @Autowired private JavaMailSender javaMailSender; //发送的名字 读取配置文件的发送邮箱 @Value("${spring.mail.username}") priv