springboot常用功能
标签:from resource 附件 nts org throw sys color art
1、常用注解
2、邮件功能
//依赖引入
org.springframework.boot
spring-boot-starter-mail
//邮件配置:application.yml 或者 application.properties
spring.mail.host=smtp.qq.com
spring.mail.username=用户名
spring.mail.password=密码
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
@Test
public void sendAttachmentsMail() throws Exception {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom("123456@qq.com");
helper.setTo("888888@qq.com");
helper.setSubject("主题:我是一封有附件的邮件");
helper.setText("有附件的邮件");
FileSystemResource file = new FileSystemResource(new File("weixin.jpg"));
helper.addAttachment("附件1.jpg", file);
helper.addAttachment("附件2.jpg", file);
mailSender.send(mimeMessage);
}
springboot常用功能
标签:from resource 附件 nts org throw sys color art
原文地址:https://www.cnblogs.com/chenweichu/p/13251517.html
评论