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

oscerd pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git


The following commit(s) were added to refs/heads/main by this push:
     new f25c604a0 chore: mail-sink can use STARTTLS (#3170) (#3174)
f25c604a0 is described below

commit f25c604a05e464e405c9340486218dc175dc8e90
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 18 09:56:34 2026 +0100

    chore: mail-sink can use STARTTLS (#3170) (#3174)
    
    Add a boolean startTls option. With protocol smtp it passes
    mail.smtp.starttls.enable and mail.smtp.starttls.required to camel-mail,
    so the connection switches to TLS before the login, as most providers
    ask for on port 587, and sending fails when the server does not offer
    STARTTLS, so the password is never sent as clear text.
    
    The option has no default: when it is not set, both parameters are left
    out of the URI, so the Kamelet behaves exactly as before, including a
    STARTTLS setting made through JVM system properties.
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../ROOT/partials/mail-sink-description.adoc       | 23 +++++++++++++++++++++-
 kamelets/mail-sink.kamelet.yaml                    | 16 +++++++++++----
 .../main/resources/META-INF/kamelets-index.json    |  2 +-
 .../main/resources/kamelets/mail-sink.kamelet.yaml | 16 +++++++++++----
 4 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/docs/modules/ROOT/partials/mail-sink-description.adoc 
b/docs/modules/ROOT/partials/mail-sink-description.adoc
index 630862ed5..00fa0d875 100644
--- a/docs/modules/ROOT/partials/mail-sink-description.adoc
+++ b/docs/modules/ROOT/partials/mail-sink-description.adoc
@@ -12,13 +12,34 @@ This Kamelet sends emails through SMTP servers with 
configurable authentication
 === Optional Configuration
 
 - **Connection Port**: SMTP port (defaults to 465)
-- **Protocol**: `smtps` (the default, TLS from the start) or `smtp` (no 
encryption)
+- **Protocol**: `smtps` (the default, TLS from the start) or `smtp` (no 
encryption, unless **STARTTLS** is on)
+- **STARTTLS**: with `smtp`, switch the connection to TLS before logging in, 
as most mail providers ask for on port 587
 - **From**: Sender email address
 - **To**: Recipients, separated by commas
 - **Subject**: Email subject line
 
 **From**, **To** and **Subject** can be left empty when every message carries 
the matching `ce-from`, `ce-to` and `ce-subject` header.
 
+=== Connecting to the SMTP Server
+
+[width="100%",cols="1,1,1,3",options="header"]
+|===
+| Protocol | STARTTLS | Usual port | Connection
+| `smtps` | (not used) | 465 | TLS from the start. The certificate of the 
server is checked.
+| `smtp` | `true` | 587 | Starts without TLS, then switches to TLS with 
STARTTLS before logging in. The certificate and the host name of the server are 
checked. Sending fails when the server does not offer STARTTLS, so the password 
is never sent as clear text.
+| `smtp` | not set or `false` | 25 | No encryption: the password and the 
emails are sent as clear text. A server that offers the login only after 
STARTTLS, such as Gmail or Office 365 on port 587, rejects the emails.
+|===
+
+For example, to send through a provider on port 587:
+
+[source,yaml]
+----
+connectionHost: smtp.example.com
+connectionPort: 587
+protocol: smtp
+startTls: true
+----
+
 === Email Headers Support
 
 The Kamelet supports various email headers through CloudEvents:
diff --git a/kamelets/mail-sink.kamelet.yaml b/kamelets/mail-sink.kamelet.yaml
index 2dc71ad33..64624cedb 100644
--- a/kamelets/mail-sink.kamelet.yaml
+++ b/kamelets/mail-sink.kamelet.yaml
@@ -39,7 +39,7 @@ spec:
 
       Output: the message is unchanged. The `CamelMailMessageId` header holds 
the ID of the email that was sent.
 
-      Good to know: each email needs a sender, recipients and a subject, from 
the options or from the `ce-from`, `ce-to` and `ce-subject` headers. The 
default protocol, `smtps`, connects with TLS and checks the certificate of the 
server. With `smtp`, the connection, the password and the emails are not 
encrypted.
+      Good to know: each email needs a sender, recipients and a subject, from 
the options or from the `ce-from`, `ce-to` and `ce-subject` headers. The 
default protocol, `smtps`, connects with TLS from the start, usually on port 
465, and checks the certificate of the server. For a server that uses STARTTLS, 
usually on port 587, set `protocol` to `smtp` and `startTls` to true: the 
connection is then encrypted before the login, the certificate and the host 
name of the server are checked, an [...]
     required:
       - connectionHost
       - username
@@ -52,16 +52,20 @@ spec:
         title: Host
         type: string
       connectionPort:
-        description: The port of the SMTP server, usually 465 for `smtps` and 
25 for `smtp`.
+        description: The port of the SMTP server, usually 465 for `smtps`, 587 
for `smtp` with `startTls`, and 25 for `smtp` without encryption.
         title: Port
         default: 465
         type: string
       protocol:
         title: Protocol
-        description: How to connect to the server. `smtps` connects with TLS 
from the start, usually on port 465. `smtp` connects without encryption, so the 
password and the emails are sent as clear text.
+        description: How to connect to the server. `smtps` connects with TLS 
from the start, usually on port 465. `smtp` connects without encryption, so the 
password and the emails are sent as clear text, unless `startTls` is true.
         type: string
         enum: ["smtp", "smtps"]
         default: "smtps"
+      startTls:
+        title: STARTTLS
+        description: Whether to switch an `smtp` connection to TLS with the 
STARTTLS command before logging in, as most mail providers ask for on port 587. 
When true, the certificate and the host name of the server are checked, and 
sending fails when the server does not offer STARTTLS, so the password is never 
sent as clear text. Only used when `protocol` is `smtp`; with `smtps` the 
connection is encrypted from the start. When false or not set, the Kamelet does 
not ask for STARTTLS, and  [...]
+        type: boolean
       username:
         title: Username
         description: The user to log in to the SMTP server as, usually an 
email address.
@@ -188,9 +192,13 @@ spec:
         - removeHeaders:
             pattern: ce-*
         - to:
-            uri: 
"{{protocol}}:{{connectionHost}}:{{connectionPort}}?subject={{?subject}}&from={{?from}}&to={{?to}}&username={{username}}&password={{password}}&useHeaderSubject=true&useHeaderFrom=true&useHeaderRecipients=true"
+            uri: 
"{{protocol}}:{{connectionHost}}:{{connectionPort}}?subject={{?subject}}&from={{?from}}&to={{?to}}&username={{username}}&password={{password}}&useHeaderSubject=true&useHeaderFrom=true&useHeaderRecipients=true&mail.smtp.starttls.enable={{?startTls}}&mail.smtp.starttls.required={{?startTls}}"
             # camel-mail ignores the Subject / From / To / Cc headers unless
             # these are enabled; without them the ce-* mappings above are
             # dead code. Reply-To stays disabled - it is not part of the
             # documented interface.
+            # startTls has no default on purpose: when it is not set the
+            # optional placeholders drop both mail.smtp.starttls.* parameters,
+            # so a STARTTLS setting from JVM system properties or the smtp
+            # component configuration still applies as before.
 
diff --git 
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json 
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index 44e2f8358..c80728efd 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -1515,7 +1515,7 @@
     "supportLevel" : "Stable",
     "title" : "Mail Sink",
     "summary" : "Sends each message as an email through an SMTP server, with 
the body as the text of the email.",
-    "description" : "Sends each message as an email through an SMTP server, 
with the body as the text of the email.\n\nUse it to send notifications, alerts 
or reports by email, for example tell a team when an order fails or send a 
daily summary.\n\nInput: the body is the text of the email. With a 
`Content-Type` header of `text/html`, the email is sent as HTML. The 
`ce-subject`, `ce-from`, `ce-to` and `ce-cc` headers set the subject, the 
sender, the recipients and the copy recipients of o [...]
+    "description" : "Sends each message as an email through an SMTP server, 
with the body as the text of the email.\n\nUse it to send notifications, alerts 
or reports by email, for example tell a team when an order fails or send a 
daily summary.\n\nInput: the body is the text of the email. With a 
`Content-Type` header of `text/html`, the email is sent as HTML. The 
`ce-subject`, `ce-from`, `ce-to` and `ce-cc` headers set the subject, the 
sender, the recipients and the copy recipients of o [...]
     "group" : "Mail",
     "namespace" : "Mail",
     "provider" : "Apache Software Foundation"
diff --git 
a/library/camel-kamelets/src/main/resources/kamelets/mail-sink.kamelet.yaml 
b/library/camel-kamelets/src/main/resources/kamelets/mail-sink.kamelet.yaml
index 2dc71ad33..64624cedb 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/mail-sink.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/mail-sink.kamelet.yaml
@@ -39,7 +39,7 @@ spec:
 
       Output: the message is unchanged. The `CamelMailMessageId` header holds 
the ID of the email that was sent.
 
-      Good to know: each email needs a sender, recipients and a subject, from 
the options or from the `ce-from`, `ce-to` and `ce-subject` headers. The 
default protocol, `smtps`, connects with TLS and checks the certificate of the 
server. With `smtp`, the connection, the password and the emails are not 
encrypted.
+      Good to know: each email needs a sender, recipients and a subject, from 
the options or from the `ce-from`, `ce-to` and `ce-subject` headers. The 
default protocol, `smtps`, connects with TLS from the start, usually on port 
465, and checks the certificate of the server. For a server that uses STARTTLS, 
usually on port 587, set `protocol` to `smtp` and `startTls` to true: the 
connection is then encrypted before the login, the certificate and the host 
name of the server are checked, an [...]
     required:
       - connectionHost
       - username
@@ -52,16 +52,20 @@ spec:
         title: Host
         type: string
       connectionPort:
-        description: The port of the SMTP server, usually 465 for `smtps` and 
25 for `smtp`.
+        description: The port of the SMTP server, usually 465 for `smtps`, 587 
for `smtp` with `startTls`, and 25 for `smtp` without encryption.
         title: Port
         default: 465
         type: string
       protocol:
         title: Protocol
-        description: How to connect to the server. `smtps` connects with TLS 
from the start, usually on port 465. `smtp` connects without encryption, so the 
password and the emails are sent as clear text.
+        description: How to connect to the server. `smtps` connects with TLS 
from the start, usually on port 465. `smtp` connects without encryption, so the 
password and the emails are sent as clear text, unless `startTls` is true.
         type: string
         enum: ["smtp", "smtps"]
         default: "smtps"
+      startTls:
+        title: STARTTLS
+        description: Whether to switch an `smtp` connection to TLS with the 
STARTTLS command before logging in, as most mail providers ask for on port 587. 
When true, the certificate and the host name of the server are checked, and 
sending fails when the server does not offer STARTTLS, so the password is never 
sent as clear text. Only used when `protocol` is `smtp`; with `smtps` the 
connection is encrypted from the start. When false or not set, the Kamelet does 
not ask for STARTTLS, and  [...]
+        type: boolean
       username:
         title: Username
         description: The user to log in to the SMTP server as, usually an 
email address.
@@ -188,9 +192,13 @@ spec:
         - removeHeaders:
             pattern: ce-*
         - to:
-            uri: 
"{{protocol}}:{{connectionHost}}:{{connectionPort}}?subject={{?subject}}&from={{?from}}&to={{?to}}&username={{username}}&password={{password}}&useHeaderSubject=true&useHeaderFrom=true&useHeaderRecipients=true"
+            uri: 
"{{protocol}}:{{connectionHost}}:{{connectionPort}}?subject={{?subject}}&from={{?from}}&to={{?to}}&username={{username}}&password={{password}}&useHeaderSubject=true&useHeaderFrom=true&useHeaderRecipients=true&mail.smtp.starttls.enable={{?startTls}}&mail.smtp.starttls.required={{?startTls}}"
             # camel-mail ignores the Subject / From / To / Cc headers unless
             # these are enabled; without them the ce-* mappings above are
             # dead code. Reply-To stays disabled - it is not part of the
             # documented interface.
+            # startTls has no default on purpose: when it is not set the
+            # optional placeholders drop both mail.smtp.starttls.* parameters,
+            # so a STARTTLS setting from JVM system properties or the smtp
+            # component configuration still applies as before.
 

Reply via email to