Files
xxxthegame/xxxthegame/src/main/java/de/oaa/xxx/mail/MailTemplateService.java
2026-03-01 22:08:15 +01:00

88 lines
3.6 KiB
Java

package de.oaa.xxx.mail;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
/**
* Generates HTML email bodies with inline styles derived from app.theme.* properties.
* Changing theme colors in application.properties automatically updates email appearance.
* (Email clients don't support external CSS or CSS variables, so styles must be inlined.)
*/
@Service
public class MailTemplateService {
@Value("${app.theme.color-bg:#1a1a2e}")
private String colorBg;
@Value("${app.theme.color-card:#16213e}")
private String colorCard;
@Value("${app.theme.color-primary:#e94560}")
private String colorPrimary;
@Value("${app.theme.color-secondary:#0f3460}")
private String colorSecondary;
@Value("${app.theme.color-text:#eeeeee}")
private String colorText;
@Value("${app.theme.color-muted:#888888}")
private String colorMuted;
@Value("${app.theme.color-success:#2ecc71}")
private String colorSuccess;
public String buildActivationMail(String name, String activationLink, String activatePageUrl, String uuid) {
return """
<!DOCTYPE html>
<html lang="de">
<body style="margin:0; padding:2rem; background:%s; font-family:'Segoe UI',Arial,sans-serif; color:%s;">
<div style="max-width:460px; margin:0 auto; background:%s; border:1px solid %s; border-radius:12px; padding:2.5rem; box-shadow:0 8px 32px rgba(0,0,0,0.5);">
<h1 style="color:%s; text-align:center; margin:0 0 1.5rem 0; font-size:1.6rem;">XXX The Game</h1>
<p style="color:%s; margin:0 0 0.75rem 0;">Moin %s,</p>
<p style="color:%s; margin:0 0 0.5rem 0;">Vielen Dank für deine Anmeldung!</p>
<p style="color:%s; margin:0 0 2rem 0;">Klick auf den Button, um deine E-Mail-Adresse zu bestätigen:</p>
<div style="text-align:center; margin:0 0 2rem 0;">
<a href="%s"
style="display:inline-block; padding:0.75rem 2.5rem; background:%s; color:#ffffff;
border-radius:6px; text-decoration:none; font-weight:600; font-size:1rem;">
E-Mail bestätigen
</a>
</div>
<hr style="border:none; border-top:1px solid %s; margin:0 0 1.5rem 0;">
<p style="color:%s; font-size:0.9em; margin:0 0 0.5rem 0;">
Falls der Button nicht funktioniert, öffne
<a href="%s" style="color:%s;">%s</a>
und gib folgenden Code ein:
</p>
<p style="font-family:monospace; font-size:1.1em; background:%s; color:%s;
padding:0.5rem 1rem; border-radius:4px; display:inline-block; margin:0.5rem 0 1.5rem 0;">
%s
</p>
<p style="color:%s; margin:0;">Viel Spaß beim Spiel!</p>
</div>
</body>
</html>
""".formatted(
colorBg, colorText,
colorCard, colorSecondary,
colorPrimary,
colorText, name,
colorText,
colorText,
activationLink, colorPrimary,
colorSecondary,
colorMuted, activatePageUrl, colorPrimary, activatePageUrl,
colorSecondary, colorText,
uuid,
colorMuted
);
}
}