26
26
import org .springframework .beans .factory .annotation .Autowired ;
27
27
import org .springframework .stereotype .Service ;
28
28
29
- import jakarta .annotation .PostConstruct ;
30
29
import jakarta .mail .Authenticator ;
31
30
import jakarta .mail .Message ;
32
31
import jakarta .mail .MessagingException ;
35
34
import jakarta .mail .Transport ;
36
35
import jakarta .mail .internet .InternetAddress ;
37
36
import jakarta .mail .internet .MimeMessage ;
37
+
38
38
import java .util .Properties ;
39
39
import java .util .concurrent .ScheduledExecutorService ;
40
- import java .util .concurrent .locks .Lock ;
41
- import java .util .concurrent .locks .ReadWriteLock ;
42
- import java .util .concurrent .locks .ReentrantReadWriteLock ;
43
40
44
41
/**
45
42
* @author Sevket Goekay <[email protected] >
@@ -52,31 +49,8 @@ public class MailService {
52
49
@ Autowired private SettingsRepository settingsRepository ;
53
50
@ Autowired private ScheduledExecutorService executorService ;
54
51
55
- private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock ();
56
- private final Lock readLock = readWriteLock .readLock ();
57
- private final Lock writeLock = readWriteLock .writeLock ();
58
-
59
- private MailSettings settings ;
60
- private Session session ;
61
-
62
- @ PostConstruct
63
- public void loadSettingsFromDB () {
64
- writeLock .lock ();
65
- try {
66
- settings = settingsRepository .getMailSettings ();
67
- } finally {
68
- writeLock .unlock ();
69
- }
70
- session = createSession (getSettings ());
71
- }
72
-
73
52
public MailSettings getSettings () {
74
- readLock .lock ();
75
- try {
76
- return this .settings ;
77
- } finally {
78
- readLock .unlock ();
79
- }
53
+ return settingsRepository .getMailSettings ();
80
54
}
81
55
82
56
public void sendTestMail () {
@@ -99,6 +73,7 @@ public void sendAsync(String subject, String body) {
99
73
100
74
public void send (String subject , String body ) throws MessagingException {
101
75
MailSettings settings = getSettings ();
76
+ Session session = createSession (getSettings ());
102
77
103
78
Message mail = new MimeMessage (session );
104
79
mail .setSubject ("[SteVe] " + subject );
0 commit comments