6. 配置application.ymlorg.springframework.boot spring-boot-starter-mail
mail:
host: smtp.qq.com
port: 587
username: 发送邮件的邮箱
password: 授权码
default-encoding: UTF-8
properties:
mail:
smtp:
socketFactoryClass: javax.net.ssl.SSLSocketFactory
debug: true
7. 编写MailService用来封装邮件的发送。
public void sendSimpleMail(String from, String to, String cc, String subject, String content) {
SimpleMailMessage simpMsg = new SimpleMailMessage();
simpMsg.setFrom(from);
simpMsg.setTo(to);
simpMsg.setCc(cc);
simpMsg.setSubject(subject);
simpMsg.setText(content);
javaMailSender.send(simpMsg);
}
配置完成后对于sendSimpleMail方法传入对应参数调用即可发送邮件。(发件人,收件人、抄送,主题,内容)



