I am trying to send an plain textemail from a Spring application using Thymeleaf.
This is my mail service:
@Override
public void sendPasswordToken(Token token) throws ServiceException {
Assert.notNull(token);
try {
Locale locale = Locale.getDefault();
final Context ctx = new Context(locale);
ctx.setVariable("url", url(token));
final MimeMessage mimeMessage = mailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(
mimeMessage, false, SpringMailConfig.EMAIL_TEMPLATE_ENCODING
);
message.setSubject("Token");
message.setTo(token.getUser().getUsername());
final String content = this.textTemplateEngine.process("text/token", ctx);
message.setText(content, false);
mailSender.send(mimeMessage);
} catch (Exception e) {
throw new ServiceException("Token has not been sent", e);
}
}
Email is sent and sent to the inbox.
This is my email template plain text:
Token ID: $ {url}
but in the supplied mailbox, the urlvariable is not replaced with a value. What for?
When I use the htmlclassic Thymeleaf HTML syntax, the variable is replaced:
<span th:text="${url}"></span>
What is the correct syntax for an email text template?
source
share