diff options
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"); |