我必须发送电子邮件与thymeleaf模板内,但我收到了明确的html代码没有所需的参数(链接)。我的错在哪里?
方法:
private void sendLetter(User user, String subject, String link, String templatePath, Locale locale) {
Context ctx = new Context(locale);
ctx.setVariables(Collections.singletonMap("link", link));
String htmlContent = templateEngine.process(templatePath, ctx);
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, "UTF-8");
message.setTo(user.getEmail());
message.setFrom(emailProperties.getFrom());
message.setSubject(subject);
message.setText(htmlContent, true);
}
catch (MessagingException e) {
e.printStackTrace();
}
javaMailSender.send(mimeMessage);
}
主题:
<a class="main_button" href="${link}">
1条答案
按热度按时间9rbhqvlz1#
你需要使用
th:href
而不是href
.更改代码
到