Spring Boot 发送邮件

关键代码

@Service
public class MailServiceImpl implements IMailService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public void sendSimpleMail() {
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom("[email protected]");
        mailMessage.setTo("[email protected]");
        mailMessage.setSubject("Hello World");
        mailMessage.setText("测试邮件");
        javaMailSender.send(mailMessage);
    }
}

你可能感兴趣的:(Spring Boot 发送邮件)