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

hansva pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new ac93db1f67 Issue #9001 : Fail the Mail action when the Mail server 
connection does not exist (#9009)
ac93db1f67 is described below

commit ac93db1f679c639f0ecd2b40a4f6f5192c9cd10e
Author: Sai Asish Y <[email protected]>
AuthorDate: Mon Oct 19 01:39:14 2026 -0700

    Issue #9001 : Fail the Mail action when the Mail server connection does not 
exist (#9009)
    
    Signed-off-by: Sai Asish Y <[email protected]>
---
 .../apache/hop/mail/workflow/actions/mail/ActionMail.java   |  7 +++++++
 .../actions/mail/messages/messages_en_US.properties         |  1 +
 .../hop/mail/workflow/actions/mail/WorkflowEntryTest.java   | 13 +++++++++++++
 3 files changed, 21 insertions(+)

diff --git 
a/plugins/misc/mail/src/main/java/org/apache/hop/mail/workflow/actions/mail/ActionMail.java
 
b/plugins/misc/mail/src/main/java/org/apache/hop/mail/workflow/actions/mail/ActionMail.java
index 48dfa13a65..1421f0bb50 100644
--- 
a/plugins/misc/mail/src/main/java/org/apache/hop/mail/workflow/actions/mail/ActionMail.java
+++ 
b/plugins/misc/mail/src/main/java/org/apache/hop/mail/workflow/actions/mail/ActionMail.java
@@ -208,6 +208,13 @@ public class ActionMail extends ActionBase implements 
Cloneable, IAction {
       try {
         connection =
             
getMetadataProvider().getSerializer(MailServerConnection.class).load(connectionName);
+        if (connection == null) {
+          logError(
+              BaseMessages.getString(PKG, 
"ActionMail.Error.ConnectionNotFound", connectionName));
+          result.setNrErrors(1L);
+          result.setResult(false);
+          return result;
+        }
         session = connection.getSession(getVariables() /*, getLogChannel()*/);
       } catch (HopException e) {
         throw new HopRuntimeException(
diff --git 
a/plugins/misc/mail/src/main/resources/org/apache/hop/mail/workflow/actions/mail/messages/messages_en_US.properties
 
b/plugins/misc/mail/src/main/resources/org/apache/hop/mail/workflow/actions/mail/messages/messages_en_US.properties
index da225c17c8..41637ae9bb 100644
--- 
a/plugins/misc/mail/src/main/resources/org/apache/hop/mail/workflow/actions/mail/messages/messages_en_US.properties
+++ 
b/plugins/misc/mail/src/main/resources/org/apache/hop/mail/workflow/actions/mail/messages/messages_en_US.properties
@@ -36,6 +36,7 @@ ActionMail.DestinationAddressBCc.Tooltip=BCc (blind carbon 
copy) recipients, sep
 ActionMail.DestinationAddressCc.Label=Cc
 ActionMail.DestinationAddressCc.Tooltip=Cc (carbon copy) recipients, separated 
by a space
 ActionMail.Encoding.Label=Encoding
+ActionMail.Error.ConnectionNotFound=Mail server connection ''{0}'' could not 
be found
 ActionMail.Error.HostNotSpecified=Unable to send the mail because the 
mail-server (SMTP host) is not specified
 ActionMail.Error.ReplyEmailNotFilled=Sender e-mail address is not filled in
 ActionMail.Fields.ContentID.Label=Content ID
diff --git 
a/plugins/misc/mail/src/test/java/org/apache/hop/mail/workflow/actions/mail/WorkflowEntryTest.java
 
b/plugins/misc/mail/src/test/java/org/apache/hop/mail/workflow/actions/mail/WorkflowEntryTest.java
index 5f13f30206..615935ec5c 100644
--- 
a/plugins/misc/mail/src/test/java/org/apache/hop/mail/workflow/actions/mail/WorkflowEntryTest.java
+++ 
b/plugins/misc/mail/src/test/java/org/apache/hop/mail/workflow/actions/mail/WorkflowEntryTest.java
@@ -17,10 +17,13 @@
 package org.apache.hop.mail.workflow.actions.mail;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 
 import org.apache.hop.core.HopClientEnvironment;
+import org.apache.hop.core.Result;
 import org.apache.hop.core.exception.HopException;
 import org.apache.hop.junit.rules.RestoreHopEngineEnvironmentExtension;
+import org.apache.hop.metadata.serializer.memory.MemoryMetadataProvider;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
@@ -59,4 +62,14 @@ class WorkflowEntryTest {
     jem.setVariable("my_pass", "Encrypted 2be98afc86aa7f2e4cb79ce10df81abdc");
     assertEquals("asdf", jem.getPassword("${my_pass}"));
   }
+
+  @Test
+  void testMissingMailServerConnectionFailsTheAction() {
+    ActionMail jem = new ActionMail();
+    jem.setMetadataProvider(new MemoryMetadataProvider());
+    jem.setConnectionName("does-not-exist");
+    Result result = jem.execute(new Result(), 0);
+    assertFalse(result.getResult());
+    assertEquals(1, result.getNrErrors());
+  }
 }

Reply via email to