Preparacion para pruebas de mandar coreros cuando aparecen ofertas nuevas. Y ediciones pequeñas en las listas
parent
cdbd05aa25
commit
1680d87945
@ -0,0 +1,7 @@
|
||||
package com.example.proyectofinal.controllers;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class EmailController {
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.example.proyectofinal.servicios;
|
||||
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MailService {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MailService.class);
|
||||
|
||||
private final JavaMailSender emailSender;
|
||||
|
||||
public MailService(JavaMailSender emailSender) {
|
||||
this.emailSender = emailSender;
|
||||
}
|
||||
|
||||
public boolean sendEmail(String to, String subject, String text) {
|
||||
LOGGER.info("Sending email...");
|
||||
return sendEmailTool(text, to, subject);
|
||||
}
|
||||
|
||||
private boolean sendEmailTool(String textMessage, String email, String subject ) {
|
||||
String cc = "empresas@ies.edu.es";
|
||||
boolean send = false;
|
||||
MimeMessage message = emailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message);
|
||||
try {
|
||||
helper.setTo(email);
|
||||
helper.setText(textMessage, true);
|
||||
helper.setSubject(subject);
|
||||
helper.setCc(cc);
|
||||
emailSender.send(message);
|
||||
send = true;
|
||||
LOGGER.info("Mail sent!");
|
||||
} catch (MessagingException e) {
|
||||
LOGGER.error("There was an error while sending the mail: {}", e.getMessage());
|
||||
}
|
||||
return send;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue