【SpringBoot】SpringBoot整合Email

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35448976/article/details/82734251

step1:

引入SpringBoot-email依赖

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-mail</artifactId>
</dependency>

step2:

配置email基本信息

spring.mail.host=smtp.qq.com
spring.mail.username=*******@qq.com
spring.mail.password=*********
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true

step3:

发送简单邮件

@Autowired
private JavaMailSender mailSender;

@Test
public void sendSimpleMail() throws Exception {
	SimpleMailMessage message = new SimpleMailMessage();
	message.setFrom("*****@qq.com");
	message.setTo("*****@qq.com");
	message.setSubject("主题:简单邮件");
	message.setText("测试邮件内容");
	mailSender.send(message);
}

猜你喜欢

转载自blog.csdn.net/qq_35448976/article/details/82734251