chore: crazy ahh email template and styles
This commit is contained in:
		
					parent
					
						
							
								110dacb6dd
							
						
					
				
			
			
				commit
				
					
						13b3443127
					
				
			
		
					 2 changed files with 163 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -1,19 +1,26 @@
 | 
			
		|||
package de.szut.casino.security.service;
 | 
			
		||||
 | 
			
		||||
import de.szut.casino.user.UserEntity;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import jakarta.mail.MessagingException;
 | 
			
		||||
import jakarta.mail.internet.MimeMessage;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Value;
 | 
			
		||||
import org.springframework.mail.SimpleMailMessage;
 | 
			
		||||
import org.springframework.core.io.ClassPathResource;
 | 
			
		||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
 | 
			
		||||
import org.springframework.mail.javamail.MimeMessageHelper;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.util.FileCopyUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStreamReader;
 | 
			
		||||
import java.io.Reader;
 | 
			
		||||
import java.nio.charset.StandardCharsets;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
public class EmailService {
 | 
			
		||||
    private JavaMailSenderImpl mailSender;
 | 
			
		||||
 | 
			
		||||
    private MailConfig mailConfig;
 | 
			
		||||
    @Value("${app.frontend-host}")
 | 
			
		||||
    private String feUrl;
 | 
			
		||||
 | 
			
		||||
    public EmailService(JavaMailSenderImpl mailSender, MailConfig mailConfig) {
 | 
			
		||||
        try {
 | 
			
		||||
| 
						 | 
				
			
			@ -31,18 +38,30 @@ public class EmailService {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    public void sendRegistrationEmail(UserEntity user) {
 | 
			
		||||
        String body = "Hallo " + user.getUsername() + ",\n\nA Willkommen bei Trustworthy Casino©! Wir freuen uns, Sie an Bord zu haben.\n\n";
 | 
			
		||||
        SimpleMailMessage mail = new SimpleMailMessage();
 | 
			
		||||
        try {
 | 
			
		||||
            String template = loadTemplate("email/registration.html");
 | 
			
		||||
            String htmlContent = template
 | 
			
		||||
                    .replace("${username}", user.getUsername())
 | 
			
		||||
                    .replace("${feUrl}", feUrl);
 | 
			
		||||
 | 
			
		||||
        mail.setFrom(mailConfig.fromAddress);
 | 
			
		||||
        mail.setSubject("Willkommen bei Trustworthy Casino©");
 | 
			
		||||
        mail.setTo(user.getEmail());
 | 
			
		||||
        mail.setText(body);
 | 
			
		||||
 | 
			
		||||
        sendEmail(mail);
 | 
			
		||||
            MimeMessage message = mailSender.createMimeMessage();
 | 
			
		||||
            MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
 | 
			
		||||
            
 | 
			
		||||
            helper.setFrom(mailConfig.fromAddress);
 | 
			
		||||
            helper.setTo(user.getEmail());
 | 
			
		||||
            helper.setSubject("Willkommen bei Trustworthy Casino©");
 | 
			
		||||
            helper.setText(htmlContent, true);
 | 
			
		||||
            
 | 
			
		||||
            mailSender.send(message);
 | 
			
		||||
        } catch (MessagingException | IOException e) {
 | 
			
		||||
            System.err.println("Failed to send registration email: " + e.getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void sendEmail(SimpleMailMessage mail) {
 | 
			
		||||
        this.mailSender.send(mail);
 | 
			
		||||
    
 | 
			
		||||
    private String loadTemplate(String templatePath) throws IOException {
 | 
			
		||||
        ClassPathResource resource = new ClassPathResource("templates/" + templatePath);
 | 
			
		||||
        try (Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) {
 | 
			
		||||
            return FileCopyUtils.copyToString(reader);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										129
									
								
								backend/src/main/resources/templates/email/registration.html
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								backend/src/main/resources/templates/email/registration.html
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,129 @@
 | 
			
		|||
<!DOCTYPE html>
 | 
			
		||||
<html lang="de">
 | 
			
		||||
<head>
 | 
			
		||||
    <meta charset="UTF-8">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
			
		||||
    <title>Willkommen bei Trustworthy Casino©</title>
 | 
			
		||||
    <style>
 | 
			
		||||
        body {
 | 
			
		||||
            font-family: 'Arial', sans-serif;
 | 
			
		||||
            line-height: 1.6;
 | 
			
		||||
            background-color: #f8fafc;
 | 
			
		||||
            color: #64748b;
 | 
			
		||||
            max-width: 600px;
 | 
			
		||||
            margin: 0 auto;
 | 
			
		||||
            padding: 20px;
 | 
			
		||||
        }
 | 
			
		||||
        .container {
 | 
			
		||||
            background-color: #0a1219;
 | 
			
		||||
            border-radius: 8px;
 | 
			
		||||
            overflow: hidden;
 | 
			
		||||
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
 | 
			
		||||
        }
 | 
			
		||||
        .header {
 | 
			
		||||
            background-color: #1a2835;
 | 
			
		||||
            padding: 20px;
 | 
			
		||||
            text-align: center;
 | 
			
		||||
        }
 | 
			
		||||
        .header h1 {
 | 
			
		||||
            color: #ffffff;
 | 
			
		||||
            margin: 0;
 | 
			
		||||
            font-size: 28px;
 | 
			
		||||
        }
 | 
			
		||||
        .content {
 | 
			
		||||
            background-color: #121e27;
 | 
			
		||||
            padding: 30px;
 | 
			
		||||
            color: #ffffff;
 | 
			
		||||
        }
 | 
			
		||||
        .footer {
 | 
			
		||||
            background-color: #1a2835;
 | 
			
		||||
            color: #94a3b8;
 | 
			
		||||
            padding: 20px;
 | 
			
		||||
            text-align: center;
 | 
			
		||||
            font-size: 0.8em;
 | 
			
		||||
        }
 | 
			
		||||
        .button {
 | 
			
		||||
            display: inline-block;
 | 
			
		||||
            background-color: #10b981;
 | 
			
		||||
            color: #ffffff;
 | 
			
		||||
            padding: 12px 24px;
 | 
			
		||||
            margin: 20px 0;
 | 
			
		||||
            text-decoration: none;
 | 
			
		||||
            border-radius: 6px;
 | 
			
		||||
            font-weight: bold;
 | 
			
		||||
            text-align: center;
 | 
			
		||||
            transition: background-color 0.3s;
 | 
			
		||||
        }
 | 
			
		||||
        .button:hover {
 | 
			
		||||
            background-color: #059669;
 | 
			
		||||
        }
 | 
			
		||||
        h2 {
 | 
			
		||||
            color: #ffffff;
 | 
			
		||||
            border-bottom: 2px solid #34d399;
 | 
			
		||||
            padding-bottom: 10px;
 | 
			
		||||
            display: inline-block;
 | 
			
		||||
        }
 | 
			
		||||
        ul {
 | 
			
		||||
            padding-left: 20px;
 | 
			
		||||
            margin: 20px 0;
 | 
			
		||||
        }
 | 
			
		||||
        li {
 | 
			
		||||
            margin-bottom: 8px;
 | 
			
		||||
            color: #94a3b8;
 | 
			
		||||
        }
 | 
			
		||||
        li::marker {
 | 
			
		||||
            color: #34d399;
 | 
			
		||||
        }
 | 
			
		||||
        .highlight {
 | 
			
		||||
            color: #fbbf24;
 | 
			
		||||
            font-weight: bold;
 | 
			
		||||
        }
 | 
			
		||||
        .divider {
 | 
			
		||||
            height: 1px;
 | 
			
		||||
            background-color: #1a2835;
 | 
			
		||||
            margin: 20px 0;
 | 
			
		||||
        }
 | 
			
		||||
        p {
 | 
			
		||||
            margin: 16px 0;
 | 
			
		||||
        }
 | 
			
		||||
    </style>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
    <div class="container">
 | 
			
		||||
        <div class="header">
 | 
			
		||||
            <h1>Trustworthy Casino<span style="color: #10b981">©</span></h1>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="content">
 | 
			
		||||
            <h2>Hallo <span class="highlight">${username}</span>,</h2>
 | 
			
		||||
            
 | 
			
		||||
            <p>Herzlich willkommen bei Trustworthy Casino©! Wir freuen uns, Sie an Bord zu haben.</p>
 | 
			
		||||
            
 | 
			
		||||
            <div class="divider"></div>
 | 
			
		||||
            
 | 
			
		||||
            <p>Bei uns erwarten Sie:</p>
 | 
			
		||||
            <ul>
 | 
			
		||||
                <li>Spannende Casino-Spiele</li>
 | 
			
		||||
                <li>Sichere Transaktionen</li>
 | 
			
		||||
                <li>Exklusive Boni und Aktionen</li>
 | 
			
		||||
            </ul>
 | 
			
		||||
            
 | 
			
		||||
            <div class="divider"></div>
 | 
			
		||||
            
 | 
			
		||||
            <p>Melden Sie sich jetzt an und beginnen Sie Ihr Spielerlebnis!</p>
 | 
			
		||||
            
 | 
			
		||||
            <div style="text-align: center;">
 | 
			
		||||
                <a href="${feUrl}/home" class="button">Jetzt Spielen</a>
 | 
			
		||||
            </div>
 | 
			
		||||
            
 | 
			
		||||
            <p>Bei Fragen stehen wir Ihnen jederzeit zur Verfügung.</p>
 | 
			
		||||
            
 | 
			
		||||
            <p>Mit freundlichen Grüßen,<br>
 | 
			
		||||
            Ihr <span style="color: #10b981;">Trustworthy Casino©</span> Team</p>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="footer">
 | 
			
		||||
            <p>© 2025 Trustworthy Casino© - Alle Rechte vorbehalten</p>
 | 
			
		||||
            <p>Diese E-Mail wurde automatisch generiert. Bitte antworten Sie nicht darauf.</p>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in a new issue