This is an automated email from the ASF dual-hosted git repository.

dominikriemer pushed a commit to branch avoid-smtp-starttls-override
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit 400c859026d46271087a55820934d54c81e51064
Author: Dominik Riemer <[email protected]>
AuthorDate: Wed Jul 8 10:38:20 2026 +0200

    fix: Avoid tls upgrade when explicitly setting mail protocol to SMTP
---
 streampipes-mail/pom.xml                           |  5 ++
 .../mail/config/MailConfigurationBuilder.java      | 28 +++++--
 .../mail/config/MailConfigurationBuilderTest.java  | 96 ++++++++++++++++++++++
 .../model/configuration/EmailConfig.java           |  1 +
 4 files changed, 122 insertions(+), 8 deletions(-)

diff --git a/streampipes-mail/pom.xml b/streampipes-mail/pom.xml
index e8c4c10f60..3e7884e146 100644
--- a/streampipes-mail/pom.xml
+++ b/streampipes-mail/pom.xml
@@ -36,6 +36,11 @@
             <groupId>org.simplejavamail</groupId>
             <artifactId>simple-java-mail</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter-api</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git 
a/streampipes-mail/src/main/java/org/apache/streampipes/mail/config/MailConfigurationBuilder.java
 
b/streampipes-mail/src/main/java/org/apache/streampipes/mail/config/MailConfigurationBuilder.java
index cdddd5d1eb..42cd7fc28a 100644
--- 
a/streampipes-mail/src/main/java/org/apache/streampipes/mail/config/MailConfigurationBuilder.java
+++ 
b/streampipes-mail/src/main/java/org/apache/streampipes/mail/config/MailConfigurationBuilder.java
@@ -24,8 +24,13 @@ import 
org.simplejavamail.api.mailer.config.TransportStrategy;
 import org.simplejavamail.mailer.MailerBuilder;
 import org.simplejavamail.mailer.internal.MailerRegularBuilderImpl;
 
+import java.util.Objects;
+
 public class MailConfigurationBuilder {
 
+  private static final String STARTTLS_ENABLE_PROPERTY = 
"mail.smtp.starttls.enable";
+  private static final String STARTTLS_REQUIRED_PROPERTY = 
"mail.smtp.starttls.required";
+
   public Mailer buildMailerFromConfig(EmailConfig config) {
     MailerRegularBuilderImpl builder = MailerBuilder
         
.withTransportStrategy(toTransportStrategy(config.getTransportStrategy()));
@@ -54,19 +59,26 @@ public class MailConfigurationBuilder {
       }
     }
 
+    disableStartTlsForPlainSmtp(config, builder);
 
     return builder.buildMailer();
 
   }
 
-  private TransportStrategy toTransportStrategy(
-      org.apache.streampipes.model.configuration.TransportStrategy strategy) {
-    if (strategy == 
org.apache.streampipes.model.configuration.TransportStrategy.SMTP) {
-      return TransportStrategy.SMTP;
-    } else if (strategy == 
org.apache.streampipes.model.configuration.TransportStrategy.SMTPS) {
-      return TransportStrategy.SMTPS;
-    } else {
-      return TransportStrategy.SMTP_TLS;
+  private void disableStartTlsForPlainSmtp(EmailConfig config,
+                                           MailerRegularBuilderImpl builder) {
+    if (config.getTransportStrategy() == 
org.apache.streampipes.model.configuration.TransportStrategy.SMTP) {
+      builder.withProperty(STARTTLS_ENABLE_PROPERTY, "false");
+      builder.withProperty(STARTTLS_REQUIRED_PROPERTY, "false");
     }
   }
+
+  TransportStrategy toTransportStrategy(
+      org.apache.streampipes.model.configuration.TransportStrategy strategy) {
+    return switch (Objects.requireNonNull(strategy, "Transport strategy must 
be configured")) {
+      case SMTP -> TransportStrategy.SMTP;
+      case SMTPS -> TransportStrategy.SMTPS;
+      case SMTP_TLS -> TransportStrategy.SMTP_TLS;
+    };
+  }
 }
diff --git 
a/streampipes-mail/src/test/java/org/apache/streampipes/mail/config/MailConfigurationBuilderTest.java
 
b/streampipes-mail/src/test/java/org/apache/streampipes/mail/config/MailConfigurationBuilderTest.java
new file mode 100644
index 0000000000..8a34ff1177
--- /dev/null
+++ 
b/streampipes-mail/src/test/java/org/apache/streampipes/mail/config/MailConfigurationBuilderTest.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.mail.config;
+
+import org.apache.streampipes.model.configuration.EmailConfig;
+import org.apache.streampipes.model.configuration.TransportStrategy;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class MailConfigurationBuilderTest {
+
+  private final MailConfigurationBuilder builder = new 
MailConfigurationBuilder();
+
+  @Test
+  public void toTransportStrategyMapsSmtpWithoutTls() {
+    Assertions.assertEquals(
+        org.simplejavamail.api.mailer.config.TransportStrategy.SMTP,
+        builder.toTransportStrategy(TransportStrategy.SMTP)
+    );
+  }
+
+  @Test
+  public void toTransportStrategyMapsSmtps() {
+    Assertions.assertEquals(
+        org.simplejavamail.api.mailer.config.TransportStrategy.SMTPS,
+        builder.toTransportStrategy(TransportStrategy.SMTPS)
+    );
+  }
+
+  @Test
+  public void toTransportStrategyMapsStartTls() {
+    Assertions.assertEquals(
+        org.simplejavamail.api.mailer.config.TransportStrategy.SMTP_TLS,
+        builder.toTransportStrategy(TransportStrategy.SMTP_TLS)
+    );
+  }
+
+  @Test
+  public void toTransportStrategyRejectsMissingStrategy() {
+    var exception = Assertions.assertThrows(
+        NullPointerException.class,
+        () -> builder.toTransportStrategy(null)
+    );
+
+    Assertions.assertEquals("Transport strategy must be configured", 
exception.getMessage());
+  }
+
+  @Test
+  public void buildMailerFromConfigDisablesStartTlsForSmtp() {
+    var mailer = 
builder.buildMailerFromConfig(makeConfig(TransportStrategy.SMTP));
+
+    Assertions.assertEquals(
+        org.simplejavamail.api.mailer.config.TransportStrategy.SMTP,
+        mailer.getTransportStrategy()
+    );
+    Assertions.assertEquals("false", 
mailer.getSession().getProperty("mail.smtp.starttls.enable"));
+    Assertions.assertEquals("false", 
mailer.getSession().getProperty("mail.smtp.starttls.required"));
+  }
+
+  @Test
+  public void buildMailerFromConfigRequiresStartTlsForSmtpTls() {
+    var mailer = 
builder.buildMailerFromConfig(makeConfig(TransportStrategy.SMTP_TLS));
+
+    Assertions.assertEquals(
+        org.simplejavamail.api.mailer.config.TransportStrategy.SMTP_TLS,
+        mailer.getTransportStrategy()
+    );
+    Assertions.assertEquals("true", 
mailer.getSession().getProperty("mail.smtp.starttls.enable"));
+    Assertions.assertEquals("true", 
mailer.getSession().getProperty("mail.smtp.starttls.required"));
+  }
+
+  private EmailConfig makeConfig(TransportStrategy transportStrategy) {
+    var config = new EmailConfig();
+    config.setTransportStrategy(transportStrategy);
+    config.setSmtpServerHost("smtp.example.org");
+    config.setSmtpServerPort(25);
+    return config;
+  }
+}
diff --git 
a/streampipes-model/src/main/java/org/apache/streampipes/model/configuration/EmailConfig.java
 
b/streampipes-model/src/main/java/org/apache/streampipes/model/configuration/EmailConfig.java
index 57e243fb13..926b45333e 100644
--- 
a/streampipes-model/src/main/java/org/apache/streampipes/model/configuration/EmailConfig.java
+++ 
b/streampipes-model/src/main/java/org/apache/streampipes/model/configuration/EmailConfig.java
@@ -51,6 +51,7 @@ public class EmailConfig {
   public static EmailConfig fromDefaults() {
     EmailConfig config = new EmailConfig();
     config.setEmailConfigured(false);
+    config.setTransportStrategy(TransportStrategy.SMTP);
 
     return config;
   }

Reply via email to