|
|
@ -3,27 +3,39 @@ package entgra.mailsender.Service;
|
|
|
|
import entgra.mailsender.DAO.MailDAO;
|
|
|
|
import entgra.mailsender.DAO.MailDAO;
|
|
|
|
import entgra.mailsender.DTO.MailModel;
|
|
|
|
import entgra.mailsender.DTO.MailModel;
|
|
|
|
import entgra.mailsender.util.PriorityQueueHolder;
|
|
|
|
import entgra.mailsender.util.PriorityQueueHolder;
|
|
|
|
|
|
|
|
import jakarta.annotation.PreDestroy;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class MailServiceImpl implements MailService {
|
|
|
|
public class MailServiceImpl implements MailService {
|
|
|
|
Logger logger = Logger.getLogger(String.valueOf(MailServiceImpl.class));
|
|
|
|
Logger logger = Logger.getLogger(String.valueOf(MailServiceImpl.class));
|
|
|
|
|
|
|
|
private volatile boolean shutdownRequested = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MailQueueService mailQueueService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// private final mailQueueService mailQueueService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PreDestroy
|
|
|
|
|
|
|
|
public void shutdown() {
|
|
|
|
|
|
|
|
shutdownRequested = true;
|
|
|
|
|
|
|
|
mailQueueService.clearOnServerShutdown();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private JavaMailSender javaMailSender;
|
|
|
|
private JavaMailSender javaMailSender;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private MailDAO mailDAO;
|
|
|
|
private MailDAO mailDAO;
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private MailQueueService mailQueueService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void sendEmail(MailModel emailModel){
|
|
|
|
public void sendEmail(MailModel emailModel){
|
|
|
@ -34,6 +46,7 @@ public class MailServiceImpl implements MailService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mailDAO.addMail(emailModel); // save the mail details in the database
|
|
|
|
mailDAO.addMail(emailModel); // save the mail details in the database
|
|
|
|
|
|
|
|
syncMailWithDB();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//here we need to check the unsent mail details
|
|
|
|
//here we need to check the unsent mail details
|
|
|
|