fix betreft email voor invite pt 3
This commit is contained in:
@@ -388,7 +388,7 @@ public class EmailService {
|
||||
"link", agendaLink
|
||||
);
|
||||
|
||||
String templatePath = "src/main/resources/templates/agenda-invite.html";
|
||||
String templatePath = "templates/agenda-invite.html";
|
||||
String htmlBody = emailTemplateService.loadTemplate(templatePath, replacements);
|
||||
|
||||
mailer.send(Mail.withHtml(recipient, "Uitnodiging om agenda te bekijken", htmlBody).setFrom("PayPoint <paypoint@melvanveen.nl>"));
|
||||
|
||||
@@ -3,23 +3,29 @@ package nl.veenm.paypoint.service;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
@ApplicationScoped
|
||||
public class EmailTemplateService {
|
||||
|
||||
public String loadTemplate(String templatePath, Map<String, String> replacements) {
|
||||
try {
|
||||
String content = Files.readString(Path.of(templatePath), StandardCharsets.UTF_8);
|
||||
try (InputStream is = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream(templatePath)) {
|
||||
|
||||
for (Map.Entry<String, String> entry : replacements.entrySet()) {
|
||||
content = content.replace("{{" + entry.getKey() + "}}", entry.getValue());
|
||||
if (is == null) {
|
||||
throw new RuntimeException("Kon e-mailtemplate niet vinden!");
|
||||
}
|
||||
|
||||
return content;
|
||||
String template = new String(is.readAllBytes(), StandardCharsets.UTF_8);
|
||||
|
||||
|
||||
for (Map.Entry<String, String> entry : replacements.entrySet()) {
|
||||
template = template.replace("{{" + entry.getKey() + "}}", entry.getValue());
|
||||
}
|
||||
|
||||
return template;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Kon e-mailtemplate niet inladen: " + templatePath, e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user