当前位置:   article > 正文

SpringBoot整合JavaMail_javamail整合springboot

javamail整合springboot

1发送简单文件

  1. <dependency>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-mail</artifactId>
  4. </dependency>//导入坐标依赖
  1. mail:
  2. host: smtp.qq.com
  3. username: 910787126@qq.com
  4. password: ******
  5. //在配置文件中配置什么形式发送文件
  1. @Autowired
  2. private JavaMailSender javaMailSender;//调用JavaMailsend进行传输内容
  3. private String me="910787126qq.com";
  4. private String you="142525231qq.com";
  5. private String subject="biaoti";
  6. private String text="wenzhang";
  7. public void save(){ //简单文件发送
  8. SimpleMailMessage mimeMessage =new SimpleMailMessage();
  9. mimeMessage.setFrom(me);
  10. mimeMessage.setTo(you);
  11. mimeMessage.setSubject(subject);
  12. mimeMessage.setText(text);
  13. javaMailSender.send(mimeMessage);
  14. }

2发送多部文件

  1. MimeMessage message=javaMailSender.createMimeMessage();
  2. MimeMessageHelper helper= new MimeMessageHelper(message,true);
  3. helper.setFrom(me);
  4. helper.setTo(you);
  5. helper.setSubject(subject);
  6. helper.setText(text,true);//可以以html形式进行上传图片链接等
  7. File file = new File("C:\\Users\\靳永超\\springboot_catch\\src\\main\\resources\\application.yml");
  8. helper.addAttachment("hggkjh",file);//附件
  9. javaMailSender.send(message);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/422120
推荐阅读
相关标签
  

闽ICP备14008679号