springboot整合mail

方法一
java自带的mail
javax.mail

 javax.mail
      mail


方法二
springframework集成的
org.springframework.boot
spring-boot-starter-mail

   
    
        org.springframework.boot
        spring-boot-starter-mail
     

toMail(EMAIL_TITLE, contentsSuccess.toString(), applyGeneralDo.getBuyerEmail());

import javax.mail.internet.MimeMessage;//

  try {
            MimeMessage mimeMessage = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
            helper.setFrom(from);
            helper.setTo(email);
            helper.setSubject(title);
            helper.setText("" + content + "", true);
            mailSender.send(mimeMessage);
        } catch (MessagingException e) {
            e.printStackTrace();
            log.error("发送邮箱失败:{}",e.getMessage());
        }

你可能感兴趣的:(springboot整合mail)