spring boot集成email
2021-01-16 04:15
标签:mem monit log boot mpi mes aging star port 1.在application.properties中增加下列属性 spring boot集成email 标签:mem monit log boot mpi mes aging star port 原文地址:https://www.cnblogs.com/sam-cheng/p/12928245.html#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);
}
}
文章标题:spring boot集成email
文章链接:http://soscw.com/index.php/essay/42544.html