我可以在MailSerivce.java中的以下sendSportsMail方法中检索参数值。
@Async
public void sendSportsMail(String name, String email, String message) {
log.debug("Sending feedback email to '{}'", email);
Locale locale = Locale.forLanguageTag("en");
String subject = messageSource.getMessage("email.sports.title", null, locale);
Context context = new Context(locale);
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process("sportsEmail", context);
sendNewEmail(email, subject, content, false, true);
}
@Async
public void sendNewEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}",
isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.warn("Email could not be sent to user '{}'", to, e);
} else {
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
}
}
}
但我不知道如何将名称,电子邮件,消息变量值解析为sportsEmail.html并进行渲染。那么任何人都可以提出想法吗? sportsEmail.html如下。
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="#{email.sports.title}">sports</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" th:href="@{|${baseUrl}/favicon.ico|}"/>
</head>
<body>
<p th:text="${name}">
</p>
</body>
</html>
$ {name}是空的。
答案 0 :(得分:2)
您必须在上下文中设置您的值,就像context.setVariable("name", "someone");
一样,请参阅Thymeleaf的文档。
gem 'bootstrap', '~> 4.0.0.beta2.1'