赞
踩
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-mail</artifactId>
- </dependency>//导入坐标依赖
- mail:
- host: smtp.qq.com
- username: 910787126@qq.com
- password: ******
- //在配置文件中配置什么形式发送文件
- @Autowired
- private JavaMailSender javaMailSender;//调用JavaMailsend进行传输内容
- private String me="910787126qq.com";
- private String you="142525231qq.com";
- private String subject="biaoti";
- private String text="wenzhang";
- public void save(){ //简单文件发送
- SimpleMailMessage mimeMessage =new SimpleMailMessage();
- mimeMessage.setFrom(me);
- mimeMessage.setTo(you);
- mimeMessage.setSubject(subject);
- mimeMessage.setText(text);
- javaMailSender.send(mimeMessage);
- }
- MimeMessage message=javaMailSender.createMimeMessage();
- MimeMessageHelper helper= new MimeMessageHelper(message,true);
- helper.setFrom(me);
- helper.setTo(you);
- helper.setSubject(subject);
- helper.setText(text,true);//可以以html形式进行上传图片链接等
- File file = new File("C:\\Users\\靳永超\\springboot_catch\\src\\main\\resources\\application.yml");
- helper.addAttachment("hggkjh",file);//附件
- javaMailSender.send(message);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。