使用java的spring-boot-starter-mail模块实现发送邮件功能
一、注入配置
在application.properties文件中,新增
spring.mail.host=smtp.qq.com
spring.mail.port=587
spring.mail.username=xx@qq.com
spring.mail.password=xxx //授权码
spring.mail.protocol=smtp
spring.mail.default-encoding=utf-8
注意如果出现以下报错,表示配置注入有问题,需要检查application.properties文件。
Field javaMailSender in com.jd.ci.service.impl.DailyServiceImpl required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.
The injection point has the following annotations:-@org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.mail.javamail.JavaMailSender' in your configuration.
二、引入依赖
>在pom.xml文件中,新增依赖
<!-- email -->
<dependency>
<groupId>org.springframework