diff --git a/src/main/java/de/rwth/idsg/steve/service/MailService.java b/src/main/java/de/rwth/idsg/steve/service/MailService.java index 70125151f..6e0e00e13 100644 --- a/src/main/java/de/rwth/idsg/steve/service/MailService.java +++ b/src/main/java/de/rwth/idsg/steve/service/MailService.java @@ -26,7 +26,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import jakarta.annotation.PostConstruct; import jakarta.mail.Authenticator; import jakarta.mail.Message; import jakarta.mail.MessagingException; @@ -35,11 +34,9 @@ import jakarta.mail.Transport; import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.MimeMessage; + import java.util.Properties; import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; /** * @author Sevket Goekay @@ -52,31 +49,8 @@ public class MailService { @Autowired private SettingsRepository settingsRepository; @Autowired private ScheduledExecutorService executorService; - private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); - private final Lock readLock = readWriteLock.readLock(); - private final Lock writeLock = readWriteLock.writeLock(); - - private MailSettings settings; - private Session session; - - @PostConstruct - public void loadSettingsFromDB() { - writeLock.lock(); - try { - settings = settingsRepository.getMailSettings(); - } finally { - writeLock.unlock(); - } - session = createSession(getSettings()); - } - public MailSettings getSettings() { - readLock.lock(); - try { - return this.settings; - } finally { - readLock.unlock(); - } + return settingsRepository.getMailSettings(); } public void sendTestMail() { @@ -99,6 +73,7 @@ public void sendAsync(String subject, String body) { public void send(String subject, String body) throws MessagingException { MailSettings settings = getSettings(); + Session session = createSession(getSettings()); Message mail = new MimeMessage(session); mail.setSubject("[SteVe] " + subject); diff --git a/src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java b/src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java index 07c6d2e40..cfe3c6452 100644 --- a/src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java +++ b/src/main/java/de/rwth/idsg/steve/web/controller/AboutSettingsController.java @@ -94,7 +94,6 @@ public String postSettings(@Valid @ModelAttribute("settingsForm") SettingsForm s } settingsRepository.update(settingsForm); - mailService.loadSettingsFromDB(); return "redirect:/manager/settings"; } @@ -107,7 +106,6 @@ public String testMail(@Valid @ModelAttribute("settingsForm") SettingsForm setti } settingsRepository.update(settingsForm); - mailService.loadSettingsFromDB(); mailService.sendTestMail(); return "redirect:/manager/settings";