SSM发送Email

来源:互联网 发布:金投顾软件怎么样 编辑:程序博客网 时间:2024/05/21 13:56

1、需要idea SpringBoot+mybatis
2、在application.properties中添加所需配置

spring.mail.host=smtp.163.com#spring.mail.port=465spring.mail.username= 邮箱用户名spring.mail.password= 邮箱密码spring.mail.default-encoding=utf-8spring.mail.properties.mail.smtp.auth=truespring.mail.properties.mail.smtp.starttls.enable=truespring.mail.properties.mail.smtp.starttls.required=true

3、在pom.xml中添加mail依赖

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

4、最后就是代码的书写

@RestControllerpublic class SendMessage {    @Autowired    private JavaMailSender sender;    @Value("${spring.mail.username}")    private String form;    @RequestMapping("MailSender")    public boolean MailSender(){        SimpleMailMessage message = new SimpleMailMessage();        message.setFrom(form);        message.setTo("178378***@qq.com");        message.setSubject("任职邀请函");        message.setText("欢迎拥有居住资格证的帅哥老五通过面试,请明天到百度公司任职,谢谢配合");        sender.send(message);        return true;    }}

5、运行idea的接口 如果看到true,就表示发送成功!

原创粉丝点击