springboot常用功能

1、常用注解

 

2、邮件功能

//依赖引入
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
</dependency>


//邮件配置: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);
}

 

posted @ 2020-07-05 20:17  N神3  阅读(485)  评论(0编辑  收藏  举报