怎么实现异步发送邮件
使用@Async注解不生效啊
@Async public void sendHTMLMail(String to, String subject, String content) throws MessagingException { MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true); mimeMessageHelper.setTo(to); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setText(content, true); mimeMessageHelper.setFrom(from); mailSender.send(mimeMessage); }
但是如果没有发送邮件的话,异步是可以生效的
@Async public void sendHTMLMail(String to, String subject, String content) throws MessagingException { for (int i = 0; i < 20; i++) { System.out.println("已经发送!!!"); } }
求解如何实现异步发送邮件?