100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Fix SMTP config issues (#1024)
Rich Turnerf48a4ec27f0b
diff --git a/manager/Dockerfile b/manager/Dockerfileindex f564f9178..a27e92cc3 100644--- a/manager/Dockerfile+++ b/manager/Dockerfile@@ -18,6 +18,7 @@ ENV OR_EMAIL_USER ${OR_EMAIL_USER}ENV OR_EMAIL_PASSWORD ${OR_EMAIL_PASSWORD}ENV OR_EMAIL_PORT ${OR_EMAIL_PORT:-587}ENV OR_EMAIL_TLS ${OR_EMAIL_TLS:-true}+ENV OR_EMAIL_PROTOCOL ${OR_EMAIL_PROTOCOL:-smtp}ENV OR_EMAIL_FROM ${OR_EMAIL_FROM}ENV OR_EMAIL_ADMIN ${OR_EMAIL_ADMIN}ENV OR_EMAIL_X_HEADERS ${OR_EMAIL_X_HEADERS}diff --git a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.javaindex 12e10fe1a..5a5c9ffd4 100644--- a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java+++ b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java@@ -42,8 +42,7 @@ import java.util.logging.Level;import java.util.logging.Logger;import java.util.stream.Collectors;-import static org.openremote.container.util.MapAccess.getBoolean;-import static org.openremote.container.util.MapAccess.getInteger;+import static org.openremote.container.util.MapAccess.*;import static org.openremote.manager.security.ManagerKeycloakIdentityProvider.KEYCLOAK_USER_ATTRIBUTE_EMAIL_NOTIFICATIONS_DISABLED;import static org.openremote.model.Constants.*;@@ -87,12 +86,12 @@ public class EmailNotificationHandler implements NotificationHandler {if (!TextUtil.isNullOrEmpty(host) && !TextUtil.isNullOrEmpty(user) && !TextUtil.isNullOrEmpty(password)) {boolean startTls = getBoolean(container.getConfig(), OR_EMAIL_TLS, OR_EMAIL_TLS_DEFAULT);-+ String protocol = startTls ? "smtp" : getString(container.getConfig(), OR_EMAIL_PROTOCOL, OR_EMAIL_PROTOCOL_DEFAULT);Properties props = new Properties();- props.put("mail.smtp.auth", true);- props.put("mail.smtp.starttls.enable", startTls);- props.put("mail.smtp.host", host);- props.put("mail.smtp.port", port);+ props.put("mail." + protocol + ".auth", true);+ props.put("mail." + protocol + ".starttls", startTls);+ props.put("mail." + protocol + ".host", host);+ props.put("mail." + protocol + ".port", port);mailSession = Session.getInstance(props, new Authenticator() {@Override@@ -102,7 +101,7 @@ public class EmailNotificationHandler implements NotificationHandler {});boolean valid;- try (Transport transport = mailSession.getTransport(startTls ? "smtps" : "smtp")) {+ try (Transport transport = mailSession.getTransport(protocol)) {transport.connect();valid = transport.isConnected();} catch (Exception e) {diff --git a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.javaindex 57fca365f..0f7a31d3c 100644--- a/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java+++ b/manager/src/main/java/org/openremote/manager/security/ManagerKeycloakIdentityProvider.java@@ -20,6 +20,11 @@package org.openremote.manager.security;import io.undertow.util.Headers;+import jakarta.persistence.Query;+import jakarta.validation.constraints.NotNull;+import jakarta.ws.rs.*;+import jakarta.ws.rs.core.Response;+import jakarta.ws.rs.core.UriBuilder;import org.apache.commons.io.IOUtils;import org.apache.http.client.utils.URIBuilder;import org.keycloak.admin.client.resource.RealmResource;@@ -56,11 +61,6 @@ import org.openremote.model.security.*;import org.openremote.model.util.TextUtil;import org.openremote.model.util.ValueUtil;-import jakarta.persistence.Query;-import jakarta.validation.constraints.NotNull;-import jakarta.ws.rs.*;-import jakarta.ws.rs.core.Response;-import jakarta.ws.rs.core.UriBuilder;import java.io.InputStream;import java.net.URISyntaxException;import java.nio.charset.StandardCharsets;@@ -1216,6 +1216,7 @@ public class ManagerKeycloakIdentityProvider extends KeycloakIdentityProvider imemailConfig.put("password", container.getConfig().getOrDefault(OR_EMAIL_PASSWORD, null));emailConfig.put("auth", container.getConfig().containsKey(OR_EMAIL_USER) ? "true" : "false");emailConfig.put("tls", Boolean.toString(getBoolean(container.getConfig(), OR_EMAIL_TLS, OR_EMAIL_TLS_DEFAULT)));+ emailConfig.put("ssl", Boolean.toString(!getBoolean(container.getConfig(), OR_EMAIL_TLS, OR_EMAIL_TLS_DEFAULT) && getString(container.getConfig(), OR_EMAIL_PROTOCOL, OR_EMAIL_PROTOCOL_DEFAULT).equals("smtps")));emailConfig.put("from", getString(container.getConfig(), OR_EMAIL_FROM, OR_EMAIL_FROM_DEFAULT));realmRepresentation.setSmtpServer(emailConfig);}diff --git a/model/src/main/java/org/openremote/model/Constants.java b/model/src/main/java/org/openremote/model/Constants.javaindex 983d61c38..b57400ea7 100644--- a/model/src/main/java/org/openremote/model/Constants.java+++ b/model/src/main/java/org/openremote/model/Constants.java@@ -60,6 +60,8 @@ public interface Constants {String OR_EMAIL_PORT = "OR_EMAIL_PORT";int OR_EMAIL_PORT_DEFAULT = 587;String OR_EMAIL_TLS = "OR_EMAIL_TLS";+ String OR_EMAIL_PROTOCOL = "OR_EMAIL_PROTOCOL";+ String OR_EMAIL_PROTOCOL_DEFAULT = "smtp";boolean OR_EMAIL_TLS_DEFAULT = true;String OR_EMAIL_X_HEADERS = "OR_EMAIL_X_HEADERS";String OR_EMAIL_FROM = "OR_EMAIL_FROM";diff --git a/profile/deploy.yml b/profile/deploy.ymlindex 24ad04314..3af13093a 100644--- a/profile/deploy.yml+++ b/profile/deploy.yml@@ -164,6 +164,7 @@ services:OR_EMAIL_PORT: ${OR_EMAIL_PORT}OR_EMAIL_TLS: ${OR_EMAIL_TLS}OR_EMAIL_X_HEADERS: ${OR_EMAIL_X_HEADERS:-} # Headers to set on all outbound emails+ OR_EMAIL_PROTOCOL: ${OR_EMAIL_PROTOCOL} # smtp or smtps for SSL (if TLS not set or is true then smtp is assumed)# Where to send admin emails toOR_EMAIL_ADMIN: ${OR_EMAIL_ADMIN}