zoukankan      html  css  js  c++  java
  • spring boot整合mail

    1.添加依赖

        </dependency>
                <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-mail</artifactId>
            </dependency>

    2.增加配置

    spring.mail.default-encoding=utf-8
    spring.mail.host=smtp.partner.outlook.cn
    spring.mail.port=587
    spring.mail.username=xxxx@xxxx.com
    spring.mail.password=123456
    spring.mail.properties.mail.smtp.auth=true
    spring.mail.properties.mail.smtp.timout=25000
    spring.mail.properties.mail.smtp.socketFactory.fallback=false
    spring.mail.properties.mail.smtp.starttls.enable=true
    spring.mail.properties.mail.smtp.protocol=smtps
    spring.mail.properties.mail.smtp.ssl.trust=smtp.partner.outlook.cn

    3.编写测试代码

    @Controller
    @RequestMapping("/api")
    public class SendMailController {
    
        @Autowired
        private MailSender mailSender;
    
        private SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    
        @RequestMapping(value = "/sendmsg", method = RequestMethod.GET)
        @ResponseBody
        public String sendMessage(){
    
            simpleMailMessage.setSubject("~-Test-~");
            simpleMailMessage.setText("test");
            simpleMailMessage.setFrom("嘻嘻嘻");
            simpleMailMessage.setTo("嘻嘻嘻");
    
            mailSender.send(simpleMailMessage);
    
            return "Mail Sent";
    
        }
    
        @RequestMapping(value = "/hello" , method = RequestMethod.GET)
        @ResponseBody
        public String getHello(){
            return "Hello";
        }
    
    }
  • 相关阅读:
    Object.keys
    数组内容深拷贝的应用
    CSS如何让页脚固定在页面底部
    vue eslint开发 关掉 tab错误提示
    input框,需要隐式显示的时候,不让它自动填充的办法
    关于BFC
    File协议与HTTP协议 以及区别
    关于缓存
    深拷贝浅拷贝 遇到了bug
    聚餐学习
  • 原文地址:https://www.cnblogs.com/davidwang456/p/6679176.html
Copyright © 2011-2022 走看看