zoukankan      html  css  js  c++  java
  • spring boot集成email

    1.在application.properties中增加下列属性

    #monitor mail config
    spring.mail.host=smtp.mxhichina.com(根据邮箱来定,此示例是阿里云企业邮箱)
    spring.mail.port=25(根据邮箱来定)
    spring.mail.username=邮箱
    spring.mail.password=

    2.gradle依赖
    compile('org.springframework.boot:spring-boot-starter-mail:2.1.3.RELEASE')

    3.创建实现
    @Autowired
    JavaMailSender mailSender;
    /**
    *send mail in the form of html
    */
    public void sendHtmlMail(String subject, String text) {
    MimeMessage message = mailSender.createMimeMessage();
    String subjectContent = config.getMailContentTemplate();
    try {
    //true means that needs to create a multipart message
    MimeMessageHelper helper = new MimeMessageHelper(message, true);
    helper.setFrom(config.getMailFrom());
    helper.setTo(config.getMailTo().split(","));
    helper.setSubject(subjectContent.replace("{monitor type}", subject));
    helper.setText(text, true);
    mailSender.send(message);
    LOG.info("send monitor mail successfully");
    } catch (MessagingException e) {
    LOG.error("send monitor mail error", e);
    }
    }
  • 相关阅读:
    第二次结对编程总结
    结对编程作业博客
    现状、经验和计划
    个人总结
    6月中旬开发心得
    读《软件开发沉思录》
    团队进度汇报
    个人课程总结
    Beta阶段总结
    冲刺第十天 1.11 FRI
  • 原文地址:https://www.cnblogs.com/sam-cheng/p/12928245.html
Copyright © 2011-2022 走看看