目录
一、开启Outlook设置
二、依赖
三、配置文件
四、代码调用
一、开启Outlook设置
开启设置如图:
二、依赖
<!-- 邮箱依赖 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId><version>2.3.2.RELEASE</version></dependency>
三、配置文件
spring:mail:username: ******@outlook.compassword: ****yourshost: smtp.office365.comport: 587properties:mail:default-encoding: UTF-8smtp:ssl:socketFactory:class: com.sun.mail.util.MailSSLSocketFactoryfallback: falseauth: truestarttls:enable: true
四、代码调用
@Service
public class EmailServiceImpl implements EmailService {@Autowiredprivate JavaMailSender mailSender;@Value("${spring.mail.username}")private String username;@Overridepublic void sendSimpleEmail(String to, String subject, String content) {SimpleMailMessage message = new SimpleMailMessage();message.setTo(to);message.setSubject(subject);message.setText(content);message.setFrom(username);mailSender.send(message);}
}
测试成功。