菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
77
0

springboot常用功能

原创
05/13 14:22
阅读数 6196

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);
}

 

发表评论

0/200
77 点赞
0 评论
收藏