diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-10 07:06:43 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-10 07:06:43 -0700 |
commit | c03b4a2ace925e6a0d7c43ce59e14ddb9cbf18a9 (patch) | |
tree | 148e1946041f4dad429cb4575b8ebfba7a3a4d85 /src/main/java/org/traccar/database | |
parent | 336d6c4353fd77ad268aaf5cfe9c0296edfb0201 (diff) | |
download | trackermap-server-c03b4a2ace925e6a0d7c43ce59e14ddb9cbf18a9.tar.gz trackermap-server-c03b4a2ace925e6a0d7c43ce59e14ddb9cbf18a9.tar.bz2 trackermap-server-c03b4a2ace925e6a0d7c43ce59e14ddb9cbf18a9.zip |
Inject mail manager
Diffstat (limited to 'src/main/java/org/traccar/database')
-rw-r--r-- | src/main/java/org/traccar/database/MailManager.java | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/database/MailManager.java b/src/main/java/org/traccar/database/MailManager.java index 21fee5ee7..54f617d5f 100644 --- a/src/main/java/org/traccar/database/MailManager.java +++ b/src/main/java/org/traccar/database/MailManager.java @@ -18,11 +18,12 @@ package org.traccar.database; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.traccar.Context; import org.traccar.Main; +import org.traccar.config.Config; import org.traccar.model.User; import org.traccar.notification.PropertiesProvider; +import javax.inject.Inject; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.MessagingException; @@ -40,6 +41,13 @@ public final class MailManager { private static final Logger LOGGER = LoggerFactory.getLogger(MailManager.class); + private final Config config; + + @Inject + public MailManager(Config config) { + this.config = config; + } + private static Properties getProperties(PropertiesProvider provider) { Properties properties = new Properties(); String host = provider.getString("mail.smtp.host"); @@ -88,7 +96,7 @@ public final class MailManager { } public boolean getEmailEnabled() { - return Context.getConfig().hasKey("mail.smtp.host"); + return config.hasKey("mail.smtp.host"); } public void sendMessage( @@ -99,11 +107,11 @@ public final class MailManager { public void sendMessage( User user, String subject, String body, MimeBodyPart attachment) throws MessagingException { Properties properties = null; - if (!Context.getConfig().getBoolean("mail.smtp.ignoreUserConfig")) { + if (!config.getBoolean("mail.smtp.ignoreUserConfig")) { properties = getProperties(new PropertiesProvider(user)); } if (properties == null || !properties.containsKey("mail.smtp.host")) { - properties = getProperties(new PropertiesProvider(Context.getConfig())); + properties = getProperties(new PropertiesProvider(config)); } if (!properties.containsKey("mail.smtp.host")) { LOGGER.warn("No SMTP configuration found"); |