Click to see the rendered email template without sending:
⚠️ Configure spring.mail.* in
application.properties before sending.
Use Mailtrap for local testing.
// 1. Build a Thymeleaf Context with variables
Context ctx = new Context();
ctx.setVariable("name", "Ana Kovač");
// 2. Process the HTML template into a String
String html = templateEngine.process("email/welcome", ctx);
// 3. Create a MIME message and set HTML body
MimeMessage msg = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(msg, true, "UTF-8");
helper.setTo("student@example.com");
helper.setSubject("Welcome!");
helper.setText(html, true); // true = isHtml
// 4. Send
mailSender.send(msg);