aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/mail
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2023-03-16 09:55:19 -0700
committerAnton Tananaev <anton@traccar.org>2023-03-16 09:55:19 -0700
commitd4816aae87600334fe798e8b50b9f11df6f0b293 (patch)
tree1882a5335a653a63136b795df6661d988d33d3e7 /src/main/java/org/traccar/mail
parent5c0962c257d51bef081d25405c972dd54035a0b2 (diff)
downloadtrackermap-server-d4816aae87600334fe798e8b50b9f11df6f0b293.tar.gz
trackermap-server-d4816aae87600334fe798e8b50b9f11df6f0b293.tar.bz2
trackermap-server-d4816aae87600334fe798e8b50b9f11df6f0b293.zip
Option for system only emails
Diffstat (limited to 'src/main/java/org/traccar/mail')
-rw-r--r--src/main/java/org/traccar/mail/LogMailManager.java10
-rw-r--r--src/main/java/org/traccar/mail/MailManager.java8
-rw-r--r--src/main/java/org/traccar/mail/SmtpMailManager.java10
3 files changed, 17 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/mail/LogMailManager.java b/src/main/java/org/traccar/mail/LogMailManager.java
index 4af68809c..5c7572b0c 100644
--- a/src/main/java/org/traccar/mail/LogMailManager.java
+++ b/src/main/java/org/traccar/mail/LogMailManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2022 - 2023 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,12 +32,14 @@ public class LogMailManager implements MailManager {
}
@Override
- public void sendMessage(User user, String subject, String body) throws MessagingException {
- sendMessage(user, subject, body, null);
+ public void sendMessage(
+ User user, boolean system, String subject, String body) throws MessagingException {
+ sendMessage(user, system, subject, body, null);
}
@Override
- public void sendMessage(User user, String subject, String body, MimeBodyPart attachment) throws MessagingException {
+ public void sendMessage(
+ User user, boolean system, String subject, String body, MimeBodyPart attachment) throws MessagingException {
LOGGER.info(
"Email sent\nTo: {}\nSubject: {}\nAttachment: {}\nBody:\n{}",
user.getEmail(), subject, attachment != null ? attachment.getFileName() : null, body);
diff --git a/src/main/java/org/traccar/mail/MailManager.java b/src/main/java/org/traccar/mail/MailManager.java
index 69efbed32..3547fd37e 100644
--- a/src/main/java/org/traccar/mail/MailManager.java
+++ b/src/main/java/org/traccar/mail/MailManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2022 - 2023 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,8 +24,10 @@ public interface MailManager {
boolean getEmailEnabled();
- void sendMessage(User user, String subject, String body) throws MessagingException;
+ void sendMessage(
+ User user, boolean system, String subject, String body) throws MessagingException;
- void sendMessage(User user, String subject, String body, MimeBodyPart attachment) throws MessagingException;
+ void sendMessage(
+ User user, boolean system, String subject, String body, MimeBodyPart attachment) throws MessagingException;
}
diff --git a/src/main/java/org/traccar/mail/SmtpMailManager.java b/src/main/java/org/traccar/mail/SmtpMailManager.java
index 4a0b7048f..8d1afbd3e 100644
--- a/src/main/java/org/traccar/mail/SmtpMailManager.java
+++ b/src/main/java/org/traccar/mail/SmtpMailManager.java
@@ -93,19 +93,21 @@ public final class SmtpMailManager implements MailManager {
return config.hasKey(Keys.MAIL_SMTP_HOST);
}
+ @Override
public void sendMessage(
- User user, String subject, String body) throws MessagingException {
- sendMessage(user, subject, body, null);
+ User user, boolean system, String subject, String body) throws MessagingException {
+ sendMessage(user, system, subject, body, null);
}
+ @Override
public void sendMessage(
- User user, String subject, String body, MimeBodyPart attachment) throws MessagingException {
+ User user, boolean system, String subject, String body, MimeBodyPart attachment) throws MessagingException {
Properties properties = null;
if (!config.getBoolean(Keys.MAIL_SMTP_IGNORE_USER_CONFIG)) {
properties = getProperties(new PropertiesProvider(user));
}
- if (properties == null) {
+ if (properties == null && (system || !config.getBoolean(Keys.MAIL_SMTP_SYSTEM_ONLY))) {
properties = getProperties(new PropertiesProvider(config));
}
if (properties == null) {