• springboot 邮件


    <!-- 邮件end -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>
    <!--freemarker模板引擎-->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>

    # JavaMailSender 邮件发送的配置s
    spring.mail.host=smtp.qq.com
    spring.mail.username=97248@qq.com
    spring.mail.password=klfncwbbhd
    spring.mail.properties.mail.smtp.auth=true
    spring.mail.properties.mail.smtp.starttls.enable=true
    spring.mail.properties.mail.smtp.starttls.required=true
    # JavaMailSender 邮件发送的配置e

    @Autowired
    private JavaMailSender mailSender; //自动注入的Bean
    @Value("${spring.mail.username}")
    private String mailFrom; //读取配置文件中的参数
    @Value("${spring.mail.password}")
    private String password; //读取配置文件中的参数
    private String mailTo = "1336956709@qq.com"; // 加载收件人地址
    @Autowired
    private FreeMarkerConfigurer freeMarkerConfigurer; //自动注入

    @RequestMapping(value = "/sendMail", method = RequestMethod.GET)
    public void sendMail() {

    // 测试

    MimeMessage message = null;
    try {
    message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(mailFrom);
    helper.setTo(mailTo);
    helper.setSubject("主题:额度发放");
    Map<String, Object> model = new HashMap<>();
    model.put("resTypeName", "服务资源");
    model.put("resName", "小车00001");
    model.put("quota", "10000");
    //读取 html 模板
    Template template = freeMarkerConfigurer.getConfiguration().getTemplate("mailtemplats/sendQuota.ftl");
    String html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
    helper.setText(html, true);
    System.out.println("发送成功");
    } catch (Exception e) {
    e.printStackTrace();
    System.out.println(e.toString());
    System.out.println("发送失败");
    }
    mailSender.send(message);
    // 测试
    }



  • 相关阅读:
    使用jQuery对象
    jQuery插件
    使用jQuery函数
    jQuery的两把利器
    初始jQuery
    BOM——特效
    BOM的介绍
    DOM——节点操作
    miaov- 自动生成正V反V大于号V小于号V楼梯等图案
    H5 -- 本地存储计数器的值 和前端校验用户
  • 原文地址:https://www.cnblogs.com/jwlfpzj/p/9234009.html
Copyright © 2020-2023  润新知