pom
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId></dependency>
配置
spring.mail.host=smtp.qq.comspring.mail.port=465spring.mail.username=from@qq.comspring.mail.password=jnliok2019spring.mail.properties.mail.smtp.ssl.enable=truespring.mail.properties.mail.smtp.auth=truespring.mail.properties.mail.smtp.starttls.enable=truespring.mail.properties.mail.smtp.starttls.required=true
Test
@RunWith(SpringRunner.class)@SpringBootTest(webEnvironment = WebEnvironment.NONE)public class MailTests { @Autowired private JavaMailSender mailSender; @Test public void sendSimpleMail() throws Exception { SimpleMailMessage message = new SimpleMailMessage(); message.setFrom("from@qq.com"); message.setTo("to@jnliok.com"); message.setSubject("主题:简单邮件"); message.setText("测试邮件内容"); mailSender.send(message); }}