@@ -19,6 +19,8 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@@ -45,9 +47,6 @@ public class EmailService {
|
||||
@Value("${server.baseurl}")
|
||||
private String baseUrl;
|
||||
|
||||
@Value("${server.front.port}")
|
||||
private String frontPort;
|
||||
|
||||
public void sendEmail(String from, String sendTo, String subject, String body) throws MessagingException {
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
||||
@@ -76,6 +75,35 @@ public class EmailService {
|
||||
sendEmail("noreply@no-copy.ru", user.getEmail(), standartAdressFrom, htmlContent);
|
||||
}
|
||||
|
||||
public void sendAutoRenewalFailedEmail(User user, String tariffName, Double price)
|
||||
throws MessagingException, IOException {
|
||||
|
||||
Map<String, String> templateData = new HashMap<>();
|
||||
templateData.put("username", user.getFullName());
|
||||
templateData.put("tariff_name", tariffName);
|
||||
templateData.put("price", String.format("%.2f", price));
|
||||
templateData.put("support_email", "support@no-copy.ru");
|
||||
|
||||
String htmlContent = loadAndProcessTemplate(templateData, "templates/failed-template.html");
|
||||
|
||||
sendEmail("noreply@no-copy.ru", user.getEmail(), standartAdressFrom, htmlContent);
|
||||
}
|
||||
|
||||
public void sendAutoRenewalSuccessEmail(User user, String tariffName, Double price, LocalDateTime nextPaymentDate)
|
||||
throws MessagingException, IOException {
|
||||
|
||||
Map<String, String> templateData = new HashMap<>();
|
||||
templateData.put("username", user.getFullName());
|
||||
templateData.put("tariff_name", tariffName);
|
||||
templateData.put("price", String.format("%.2f", price));
|
||||
templateData.put("renewal_date", LocalDateTime.now().format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm")));
|
||||
templateData.put("next_payment_date", nextPaymentDate.format(DateTimeFormatter.ofPattern("dd.MM.yyyy")));
|
||||
|
||||
String htmlContent = loadAndProcessTemplate(templateData, "templates/auto-renewal-success.html");
|
||||
|
||||
sendEmail("noreply@no-copy.ru", user.getEmail(), standartAdressFrom, htmlContent);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public EmailVerificationToken createEmailVerificationToken(AuthToken authToken) {
|
||||
EmailVerificationToken existingToken = emailVerificationTokenRepository
|
||||
|
||||
Reference in New Issue
Block a user