This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 6569942fb chore: the mail Kamelets can choose, move and delete the
emails they read, and mail-sink takes cc, bcc, replyTo and contentType (#3170)
(#3216)
6569942fb is described below
commit 6569942fb25d16f213d1df28e438b305c5ecace4
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Nov 18 22:31:22 2026 +0100
chore: the mail Kamelets can choose, move and delete the emails they read,
and mail-sink takes cc, bcc, replyTo and contentType (#3170) (#3216)
mail-imap-source and ms-exchange-online-imap-oauth-source take
folderName, unseen, delete, moveTo, copyTo, peek, skipFailedMessage
and four search options: searchFrom, searchTo, searchSubject and
searchSubjectOrBody. The search options map to the component's
searchTerm.* parameters, so no bean is needed. With a search, the
component takes unseen from the search and not from the endpoint, so
unseen is passed to both. All new options are optional placeholders
without a default: when they are not set, the endpoint URI is the same
as before. Folder names and search texts go through RAW(), and the
folder options reject % and *, which IMAP reads as wildcards.
mail-sink takes cc, bcc, replyTo and contentType. The mail component
takes the recipients either all from the To, Cc and Bcc headers or,
when there is none, all from the options, so a ce-to or ce-cc header
dropped the to, cc and bcc options: with the to option and a ce-cc
header, the email went to the copy recipient only. The Kamelet now
puts the to, cc and bcc options into the headers, so that a ce-to or
ce-cc header replaces only its own option and bcc is always kept.
Bcc and Reply-To still cannot come from the message. When contentType
is set, it wins over a Content-Type header, which sources such as
timer-source set to text/plain on every message.
A trust store for a private certificate authority is set with the
camel.ssl application properties and
camel.component.imaps/smtps/smtp.useGlobalSslContextParameters; the
descriptions and the doc pages say how. maxMessagesPerPoll is left
out: the fetchSize option already limits the emails of each check,
and the component ignores maxMessagesPerPoll while fetchSize is set.
The mail-sink Citrus test now also checks cc, Reply-To and the
content type.
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../partials/mail-imap-source-description.adoc | 64 +++++++++++++++++-
.../ROOT/partials/mail-sink-description.adoc | 43 +++++++++++-
...hange-online-imap-oauth-source-description.adoc | 33 ++++++++-
kamelets/mail-imap-source.kamelet.yaml | 76 ++++++++++++++++++++-
kamelets/mail-sink.kamelet.yaml | 78 ++++++++++++++++++++--
...-exchange-online-imap-oauth-source.kamelet.yaml | 76 ++++++++++++++++++++-
.../main/resources/META-INF/kamelets-index.json | 10 +--
.../kamelets/mail-imap-source.kamelet.yaml | 76 ++++++++++++++++++++-
.../main/resources/kamelets/mail-sink.kamelet.yaml | 78 ++++++++++++++++++++--
...-exchange-online-imap-oauth-source.kamelet.yaml | 76 ++++++++++++++++++++-
.../resources/mail/mail-sink-route.citrus.it.yaml | 18 ++++-
.../src/test/resources/mail/mail-sink-route.yaml | 4 ++
12 files changed, 602 insertions(+), 30 deletions(-)
diff --git a/docs/modules/ROOT/partials/mail-imap-source-description.adoc
b/docs/modules/ROOT/partials/mail-imap-source-description.adoc
index 565fce014..86c0c6d9d 100644
--- a/docs/modules/ROOT/partials/mail-imap-source-description.adoc
+++ b/docs/modules/ROOT/partials/mail-imap-source-description.adoc
@@ -2,7 +2,7 @@
=== Authentication
-This Kamelet requires username and password authentication to connect to an
IMAP mail server. It always connects with TLS (IMAPS) and checks the
certificate of the server.
+This Kamelet requires username and password authentication to connect to an
IMAP mail server. It always connects with TLS (IMAPS) and checks the
certificate and the host name of the server.
=== Configuration
@@ -14,8 +14,29 @@ The Mail IMAP Source Kamelet supports the following
configurations:
- **Password** (`password`): Email account password (required)
- **Fetch Size** (`fetchSize`): The most emails to read at each check
(default: 10, -1 for no limit)
- **Delay** (`delay`): Milliseconds between two checks of the mailbox
(default: 60000)
+- **Folder Name** (`folderName`): The folder to read (default: `INBOX`)
+- **Unread Only** (`unseen`): Set to `false` to read the emails that are
already read too
+- **Delete** (`delete`), **Move To** (`moveTo`), **Copy To** (`copyTo`): What
to do with each email once it is processed
+- **Peek** (`peek`): Keeps an email unread while it is processed (on by
default)
+- **Skip Failed Email** (`skipFailedMessage`): Skips an email that cannot be
read at all
+- **Search From**, **Search To**, **Search Subject**, **Search Subject or
Body** (`searchFrom`, `searchTo`, `searchSubject`, `searchSubjectOrBody`): Read
only the emails that match
-The Kamelet reads only the unread emails of the `INBOX` folder, and marks each
one as read. Emails are not deleted.
+By default, the Kamelet reads only the unread emails of the `INBOX` folder,
and marks each one as read. Emails are not deleted.
+
+=== What Happens to an Email
+
+[width="100%",cols="2,3,3",options="header"]
+|===
+| Options | Once the email is processed | When processing the email fails
+| none | Stays in the folder, marked as read. | Stays unread, and is read
again at the next check.
+| `delete: true` | Deleted from the folder. | Stays unread, and is read again
at the next check.
+| `moveTo: Processed` | Moved to `Processed`, marked as read. The folder is
created when it does not exist. | Stays unread, and is read again at the next
check.
+| `copyTo: Archive` | Stays in the folder, marked as read. An unread copy is
put in `Archive`. | Stays unread, not copied, and is read again at the next
check.
+| `peek: false` | As above. | Marked as read, and not read again.
+| `unseen: false` without `delete` or `moveTo` | Stays in the folder, and is
read again at every check. | Read again at every check.
+|===
+
+An email that cannot be read at all, such as one with a broken format, fails
the whole check of the mailbox, so no email is read until it is removed. With
`skipFailedMessage: true`, it is skipped and stays unread, and the other emails
are read.
=== Output Format
@@ -56,6 +77,45 @@ The body is the text of the email; for an email with several
parts, it is the te
uri: "kamelet:log-sink"
----
+=== Example: Invoices from a Supplier
+
+Read the emails from one sender with `invoice` in the subject, from a
subfolder, and move each one to `Processed` once it is processed:
+
+[source,yaml,subs='+attributes,macros']
+----
+- route:
+ from:
+ uri: "kamelet:mail-imap-source"
+ parameters:
+ connectionHost: "mail.example.com"
+ connectionPort: "993"
+ username: "[email protected]"
+ password: "mailpass"
+ folderName: "INBOX/Suppliers"
+ searchFrom: "[email protected]"
+ searchSubject: "invoice"
+ moveTo: "Processed"
+ steps:
+ - to:
+ uri: "kamelet:log-sink"
+----
+
+Every search option that is set must match. The mail server does the search,
without telling upper and lower case apart. Some servers match only a whole
address in `searchFrom` and `searchTo`, so give the whole address.
+
+=== Trusting a Private Certificate Authority
+
+The certificate of the server is checked against the certificate authorities
that Java trusts. For a server with a certificate from a private or self-signed
authority, put that authority in a trust store file (JKS or PKCS12), and set
these application properties with Camel JBang or Camel Main:
+
+[source,properties]
+----
+camel.ssl.enabled=true
+camel.ssl.trustStore=file:/etc/mail/truststore.p12
+camel.ssl.trustStorePassword=changeit
+camel.component.imaps.useGlobalSslContextParameters=true
+----
+
+That trust store then replaces the one of Java for every IMAPS connection of
the application. The host name of the server is still checked.
+
=== Security Considerations
- Use app-specific passwords for Gmail and similar providers
diff --git a/docs/modules/ROOT/partials/mail-sink-description.adoc
b/docs/modules/ROOT/partials/mail-sink-description.adoc
index 00fa0d875..a7b61894f 100644
--- a/docs/modules/ROOT/partials/mail-sink-description.adoc
+++ b/docs/modules/ROOT/partials/mail-sink-description.adoc
@@ -17,6 +17,10 @@ This Kamelet sends emails through SMTP servers with
configurable authentication
- **From**: Sender email address
- **To**: Recipients, separated by commas
- **Subject**: Email subject line
+- **Cc**: Copy recipients, separated by commas
+- **Bcc**: Blind copy recipients, separated by commas
+- **Reply To**: The address that replies go to, in place of the sender
+- **Content Type**: The type of the text in the body, such as `text/html`
(default: plain text)
**From**, **To** and **Subject** can be left empty when every message carries
the matching `ce-from`, `ce-to` and `ce-subject` header.
@@ -45,10 +49,43 @@ startTls: true
The Kamelet supports various email headers through CloudEvents:
- `ce-subject`: Override email subject
- `ce-from`: Override sender address
-- `ce-to`: Override recipient address
-- `ce-cc`: Add CC recipients
+- `ce-to`: Override the `to` recipients
+- `ce-cc`: Override the `cc` recipients
-Other mail headers on the message, such as `To`, `Cc` or `Bcc`, are removed. A
`Content-Type` header of `text/html` sends the body as an HTML email.
+Each header replaces only its own option: with a `ce-to` header, the `cc` and
`bcc` recipients of the options still receive the email. Other mail headers on
the message, such as `To`, `Cc`, `Bcc` or `Reply-To`, are removed, so the blind
copy recipients and the reply address come only from the options. A
`Content-Type` header, such as `text/html`, sets the type of one email when the
`contentType` option is not set; when it is set, the header is not used.
+
+For example, to send HTML emails to a team, with a copy to a manager, a blind
copy to an archive mailbox, and replies to the support address:
+
+[source,yaml]
+----
+connectionHost: smtp.example.com
+username: [email protected]
+password: secret
+from: [email protected]
+to: [email protected]
+cc: [email protected]
+bcc: [email protected]
+replyTo: [email protected]
+contentType: text/html
+subject: Order failed
+----
+
+=== Trusting a Private Certificate Authority
+
+The certificate of the server is checked against the certificate authorities
that Java trusts. For a server with a certificate from a private or self-signed
authority, put that authority in a trust store file (JKS or PKCS12), and set
these application properties with Camel JBang or Camel Main:
+
+[source,properties]
+----
+camel.ssl.enabled=true
+camel.ssl.trustStore=file:/etc/mail/truststore.p12
+camel.ssl.trustStorePassword=changeit
+# with protocol smtps
+camel.component.smtps.useGlobalSslContextParameters=true
+# with protocol smtp and startTls true
+camel.component.smtp.useGlobalSslContextParameters=true
+----
+
+That trust store then replaces the one of Java for every connection of the
application with that protocol. The host name of the server is still checked.
=== Usage
diff --git
a/docs/modules/ROOT/partials/ms-exchange-online-imap-oauth-source-description.adoc
b/docs/modules/ROOT/partials/ms-exchange-online-imap-oauth-source-description.adoc
index 0291e8067..4aab2ae93 100644
---
a/docs/modules/ROOT/partials/ms-exchange-online-imap-oauth-source-description.adoc
+++
b/docs/modules/ROOT/partials/ms-exchange-online-imap-oauth-source-description.adoc
@@ -11,7 +11,7 @@ From the app registration, use the Directory (tenant) ID as
`tenantId`, the Appl
=== Output format
-The Kamelet reads the unread emails of the `INBOX` folder, one message per
email, and marks each email as read. Emails stay in the mailbox. The body is
the text of the email; for an email with several parts (text and HTML,
attachments), it is the multipart content, which reads as the text of the first
part. The headers of the email, such as `Subject`, `From`, `To` and `Date`, are
copied to the message.
+By default, the Kamelet reads the unread emails of the `INBOX` folder, one
message per email, and marks each email as read. Emails stay in the mailbox.
The body is the text of the email; for an email with several parts (text and
HTML, attachments), it is the multipart content, which reads as the text of the
first part. The headers of the email, such as `Subject`, `From`, `To` and
`Date`, are copied to the message.
=== Usage example
@@ -29,3 +29,34 @@ The Kamelet reads the unread emails of the `INBOX` folder,
one message per email
- to:
uri: "kamelet:log-sink"
----
+
+=== Choosing and Moving Emails
+
+These options work as in `mail-imap-source`:
+
+- `folderName`: the folder to read, such as `Inbox/Orders` (default: `INBOX`).
+- `unseen`: set to `false` to read the emails that are already read too.
+- `delete`, `moveTo`, `copyTo`: what to do with each email once it is
processed. A folder in `moveTo` or `copyTo` is created when it does not exist.
+- `peek`: keeps an email unread while it is processed, so that an email whose
processing fails is read again at the next check (on by default).
+- `skipFailedMessage`: skips an email that cannot be read at all, such as one
with a broken format, instead of failing every check of the mailbox.
+- `searchFrom`, `searchTo`, `searchSubject`, `searchSubjectOrBody`: read only
the emails that match. Every search option that is set must match.
+
+For example, to read the orders from one sender and move each one to the
`Processed` folder:
+
+[source,yaml,subs='+attributes,macros']
+----
+- route:
+ from:
+ uri: "kamelet:ms-exchange-online-imap-oauth-source"
+ parameters:
+ tenantId: "11111111-2222-3333-4444-555555555555"
+ clientId: "{{exchange.clientId}}"
+ clientSecret: "{{exchange.clientSecret}}"
+ username: "[email protected]"
+ searchFrom: "[email protected]"
+ searchSubject: "order"
+ moveTo: "Processed"
+ steps:
+ - to:
+ uri: "kamelet:log-sink"
+----
diff --git a/kamelets/mail-imap-source.kamelet.yaml
b/kamelets/mail-imap-source.kamelet.yaml
index da08f5be8..5c89d1da9 100644
--- a/kamelets/mail-imap-source.kamelet.yaml
+++ b/kamelets/mail-imap-source.kamelet.yaml
@@ -31,13 +31,13 @@ spec:
definition:
title: "Mail IMAP Source"
description: |-
- Reads the unread emails in the inbox of a mailbox over IMAP, one message
per email, and marks each email as read.
+ Reads the unread emails in a folder of a mailbox over IMAP, by default
the inbox, one message per email, and marks each email as read.
Use it to start a flow from incoming email, for example turn support
requests into tickets, or process the orders and invoices that customers send
by email. For a Microsoft 365 mailbox that needs an OAuth login, use
`ms-exchange-online-imap-oauth-source`, and for Gmail through its API, use
`google-mail-source`.
Output: the body is the text of the email. For an email with several
parts, such as text and HTML or attachments, it is the text of the first part;
attachments are not in the body. The `ce-subject`, `ce-from`, `ce-to` and
`ce-cc` headers hold the subject and the addresses, and the headers of the
email, such as `Subject`, `From`, `Date` and `Message-ID`, are copied too.
- Good to know: emails stay in the mailbox, marked as read, and emails
that are already read are skipped. It reads only the `INBOX` folder. It always
connects with TLS (IMAPS) and checks the certificate of the server. It checks
for new email once a minute by default (`delay`).
+ Good to know: by default it reads the `INBOX` folder, emails stay in the
folder, marked as read, and emails that are already read are skipped. Set
`delete` or `moveTo` to remove the emails once they are processed, `unseen` to
false to read the emails that are already read too, and the search options,
such as `searchFrom` or `searchSubject`, to read only some emails; an email
must match every search option that is set. An email whose processing fails
stays unread and is read again a [...]
required:
- connectionHost
- connectionPort
@@ -78,6 +78,64 @@ spec:
description: How long to wait between two checks of the mailbox, in
milliseconds. The default, 60000, is one minute.
type: integer
default: 60000
+ folderName:
+ title: Folder Name
+ description: The folder to read the emails from. When it is not set,
the Kamelet reads the `INBOX` folder. A subfolder is written with the separator
of the server, usually `/` or `.`, such as `INBOX/Orders`. When the folder does
not exist, each check of the mailbox fails with a warning in the log.
+ type: string
+ example: INBOX/Orders
+ pattern: "^[^\\r\\n%*]+$"
+ unseen:
+ title: Unread Only
+ description: Whether to read only the emails that are not marked as
read. When it is not set, only unread emails are read. When false, the emails
that are already read are read too; without `delete` or `moveTo`, every email
in the folder is then read again at each check.
+ type: boolean
+ delete:
+ title: Delete
+ description: Whether to delete each email from the folder once it is
processed. When it is not set, emails stay in the folder, marked as read. An
email whose processing fails is not deleted.
+ type: boolean
+ moveTo:
+ title: Move To
+ description: The folder to move each email to once it is processed,
such as `Processed`. The folder is created when it does not exist. The email is
then no longer in the folder that is read. An email whose processing fails is
not moved.
+ type: string
+ example: Processed
+ pattern: "^[^\\r\\n%*]+$"
+ copyTo:
+ title: Copy To
+ description: The folder to copy each email to once it is processed,
such as `Archive`. The folder is created when it does not exist. The email also
stays in the folder that is read, and the copy is not marked as read. An email
whose processing fails is not copied.
+ type: string
+ example: Archive
+ pattern: "^[^\\r\\n%*]+$"
+ peek:
+ title: Peek
+ description: Whether to keep an email unread while it is processed, so
that an email whose processing fails stays unread and is read again at the next
check. When it is not set, this is on. When false, an email is marked as read
as soon as it is read, and an email whose processing fails is not read again.
+ type: boolean
+ skipFailedMessage:
+ title: Skip Failed Email
+ description: Whether to skip an email that cannot be read at all, such
as one with a broken format, and go on with the other emails. When it is not
set, such an email fails the whole check of the mailbox, again at each check,
and no email is read until it is removed from the folder. A skipped email stays
in the folder, unread, and no error is logged.
+ type: boolean
+ searchFrom:
+ title: Search From
+ description: Read only the emails whose sender contains this text,
such as `[email protected]`. Upper and lower case are the same. The mail
server does the search, and some servers match only a whole address, so give
the whole address to be safe.
+ type: string
+ example: [email protected]
+ pattern: "^[^\\r\\n]+$"
+ searchTo:
+ title: Search To
+ description: Read only the emails whose `To` recipients contain this
text, such as an address. The copy recipients (`Cc`) are not searched. Upper
and lower case are the same. The mail server does the search, and some servers
match only a whole address, so give the whole address to be safe.
+ type: string
+ example: [email protected]
+ pattern: "^[^\\r\\n]+$"
+ searchSubject:
+ title: Search Subject
+ description: Read only the emails whose subject contains this text,
such as `invoice`. Upper and lower case are the same.
+ type: string
+ example: invoice
+ pattern: "^[^\\r\\n]+$"
+ searchSubjectOrBody:
+ title: Search Subject or Body
+ description: Read only the emails whose subject or text contains this
text, such as `refund`. Upper and lower case are the same.
+ type: string
+ example: refund
+ pattern: "^[^\\r\\n]+$"
dataTypes:
out:
headers:
@@ -110,6 +168,20 @@ spec:
fetchSize: "{{fetchSize}}"
password: "RAW({{password}})"
username: "RAW({{username}})"
+ folderName: "RAW({{?folderName}})"
+ unseen: "{{?unseen}}"
+ delete: "{{?delete}}"
+ moveTo: "RAW({{?moveTo}})"
+ copyTo: "RAW({{?copyTo}})"
+ peek: "{{?peek}}"
+ skipFailedMessage: "{{?skipFailedMessage}}"
+ # With a search, the component takes unseen from the search, so
+ # pass it there too.
+ searchTerm.unseen: "{{?unseen}}"
+ searchTerm.from: "RAW({{?searchFrom}})"
+ searchTerm.to: "RAW({{?searchTo}})"
+ searchTerm.subject: "RAW({{?searchSubject}})"
+ searchTerm.subjectOrBody: "RAW({{?searchSubjectOrBody}})"
steps:
- setHeader:
name: ce-subject
diff --git a/kamelets/mail-sink.kamelet.yaml b/kamelets/mail-sink.kamelet.yaml
index 64624cedb..33696c430 100644
--- a/kamelets/mail-sink.kamelet.yaml
+++ b/kamelets/mail-sink.kamelet.yaml
@@ -35,11 +35,11 @@ spec:
Use it to send notifications, alerts or reports by email, for example
tell a team when an order fails or send a daily summary.
- Input: 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 one email, in place of the options; several addresses are
separated by commas. Other mail headers on the message, such as `To` or `Bcc`,
are removed and not used.
+ Input: the body is the text of the email. It is sent as the type in
`contentType`; when that is not set, as the type in the `Content-Type` header,
such as `text/html` for an HTML email, and otherwise as plain text. The
`ce-subject`, `ce-from`, `ce-to` and `ce-cc` headers set the subject, the
sender, the recipients and the copy recipients of one email, each in place of
its option; several addresses are separated by commas. Other mail headers on
the message, such as `To`, `Bcc` or `R [...]
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 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 [...]
+ 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
@@ -94,6 +94,28 @@ spec:
example: Order failed
title: Subject
type: string
+ cc:
+ title: Cc
+ description: The copy recipients of the emails; several addresses are
separated by commas. The `ce-cc` header replaces it for one message.
+ example: [email protected]
+ type: string
+ bcc:
+ title: Bcc
+ description: The blind copy recipients of the emails; several
addresses are separated by commas. They receive each email, and the other
recipients do not see them. Messages cannot change them.
+ example: [email protected]
+ type: string
+ replyTo:
+ title: Reply To
+ description: The address that replies to the emails go to, in place of
the sender; several addresses are separated by commas. Messages cannot change
it.
+ example: [email protected]
+ type: string
+ pattern: "^[^\\r\\n]*@[^\\r\\n]*$"
+ contentType:
+ title: Content Type
+ description: The type of the text in the body of every email, such as
`text/html` to send HTML emails. When it is set, the `Content-Type` header of
the message is not used. When it is not set, that header sets the type, and
without it the emails are sent as plain text (`text/plain`). Some sources set
that header, such as `timer-source`, which sets `text/plain` by default.
+ example: text/html
+ type: string
+ pattern: "^[A-Za-z0-9.+-]+/[A-Za-z0-9.+-]+(\\s*;.*)?$"
dataTypes:
in:
headers:
@@ -111,11 +133,11 @@ spec:
type: string
ce-cc:
title: Cc
- description: The copy recipients of the email, separated by commas.
+ description: The copy recipients of the email, separated by commas,
in place of the `cc` option.
type: string
Content-Type:
title: Content Type
- description: The type of the text in the body, such as `text/html`
to send an HTML email.
+ description: The type of the text in the body, such as `text/html`
to send an HTML email. Not used when the `contentType` option is set.
type: string
out:
headers:
@@ -167,6 +189,10 @@ spec:
expression:
simple:
expression: "${header[ce-from]}"
+ # The mail component takes the recipients either all from the To,
+ # Cc and Bcc headers or, when there is none, all from the to, cc and
+ # bcc options. Put the options into the headers, so that a ce-to or
+ # ce-cc header replaces only its own option, and bcc is always kept.
- choice:
when:
- expression:
@@ -178,6 +204,15 @@ spec:
expression:
simple:
expression: "${header[ce-to]}"
+ - expression:
+ constant:
+ expression: "{{?to}}"
+ steps:
+ - setHeader:
+ name: To
+ expression:
+ constant:
+ expression: "{{?to}}"
- choice:
when:
- expression:
@@ -189,10 +224,43 @@ spec:
expression:
simple:
expression: "${header[ce-cc]}"
+ - expression:
+ constant:
+ expression: "{{?cc}}"
+ steps:
+ - setHeader:
+ name: Cc
+ expression:
+ constant:
+ expression: "{{?cc}}"
+ - choice:
+ when:
+ - expression:
+ constant:
+ expression: "{{?bcc}}"
+ steps:
+ - setHeader:
+ name: Bcc
+ expression:
+ constant:
+ expression: "{{?bcc}}"
+ # A contentType option is the type of every email: a Content-Type
+ # header from an earlier step, such as the text/plain one of
+ # timer-source, must not replace it.
+ - choice:
+ when:
+ - expression:
+ constant:
+ expression: "{{?contentType}}"
+ steps:
+ - removeHeader:
+ name: Content-Type
+ - removeHeader:
+ name: CamelMailContentType
- removeHeaders:
pattern: ce-*
- to:
- 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}}"
+ 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}}&replyTo=RAW({{?replyTo}})&contentType=RAW({{?contentType}})"
# 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
diff --git a/kamelets/ms-exchange-online-imap-oauth-source.kamelet.yaml
b/kamelets/ms-exchange-online-imap-oauth-source.kamelet.yaml
index 1782de5eb..d1d6e291d 100644
--- a/kamelets/ms-exchange-online-imap-oauth-source.kamelet.yaml
+++ b/kamelets/ms-exchange-online-imap-oauth-source.kamelet.yaml
@@ -31,13 +31,13 @@ spec:
definition:
title: "Microsoft Exchange IMAP OAuth2 Source"
description: |-
- Reads the unread emails in the inbox of a Microsoft 365 (Exchange
Online) mailbox over IMAP, logging in with OAuth 2.0, and marks each email as
read.
+ Reads the unread emails in a folder of a Microsoft 365 (Exchange Online)
mailbox over IMAP, by default the inbox, logging in with OAuth 2.0, and marks
each email as read.
Use it to process the email that arrives in a Microsoft 365 mailbox
where login with a password is turned off, for example orders, invoices or
support requests sent to a shared address. For other mail servers, use
`mail-imap-source`.
Output: the body is the text of the email. For an email with several
parts, such as text and HTML or attachments, it is the content of the parts,
which the next step reads as the text of the first part. The headers of the
email, such as `Subject`, `From`, `To` and `Date`, are copied to the message.
- Good to know: it logs in as an application, not as a person: register an
application in Microsoft Entra ID (formerly Azure Active Directory) with a
client secret, and allow it to read the mailbox over IMAP. It gets a token when
it starts, so with wrong credentials, such as an unknown tenant ID, the
integration does not start. Emails stay in the mailbox, marked as read, and
emails that are already read are skipped. It reads only the `INBOX` folder,
over TLS, and checks for new email [...]
+ Good to know: it logs in as an application, not as a person: register an
application in Microsoft Entra ID (formerly Azure Active Directory) with a
client secret, and allow it to read the mailbox over IMAP. It gets a token when
it starts, so with wrong credentials, such as an unknown tenant ID, the
integration does not start. By default it reads the `INBOX` folder, emails stay
in the folder, marked as read, and emails that are already read are skipped.
Set `delete` or `moveTo` to r [...]
required:
- tenantId
- clientId
@@ -90,6 +90,64 @@ spec:
description: How long to wait between two checks of the mailbox, in
milliseconds. The default, 60000, is one minute.
type: integer
default: 60000
+ folderName:
+ title: Folder Name
+ description: The folder to read the emails from. When it is not set,
the Kamelet reads the `INBOX` folder. A subfolder is written with the separator
of the server, usually `/` or `.`, such as `INBOX/Orders`. When the folder does
not exist, each check of the mailbox fails with a warning in the log.
+ type: string
+ example: INBOX/Orders
+ pattern: "^[^\\r\\n%*]+$"
+ unseen:
+ title: Unread Only
+ description: Whether to read only the emails that are not marked as
read. When it is not set, only unread emails are read. When false, the emails
that are already read are read too; without `delete` or `moveTo`, every email
in the folder is then read again at each check.
+ type: boolean
+ delete:
+ title: Delete
+ description: Whether to delete each email from the folder once it is
processed. When it is not set, emails stay in the folder, marked as read. An
email whose processing fails is not deleted.
+ type: boolean
+ moveTo:
+ title: Move To
+ description: The folder to move each email to once it is processed,
such as `Processed`. The folder is created when it does not exist. The email is
then no longer in the folder that is read. An email whose processing fails is
not moved.
+ type: string
+ example: Processed
+ pattern: "^[^\\r\\n%*]+$"
+ copyTo:
+ title: Copy To
+ description: The folder to copy each email to once it is processed,
such as `Archive`. The folder is created when it does not exist. The email also
stays in the folder that is read, and the copy is not marked as read. An email
whose processing fails is not copied.
+ type: string
+ example: Archive
+ pattern: "^[^\\r\\n%*]+$"
+ peek:
+ title: Peek
+ description: Whether to keep an email unread while it is processed, so
that an email whose processing fails stays unread and is read again at the next
check. When it is not set, this is on. When false, an email is marked as read
as soon as it is read, and an email whose processing fails is not read again.
+ type: boolean
+ skipFailedMessage:
+ title: Skip Failed Email
+ description: Whether to skip an email that cannot be read at all, such
as one with a broken format, and go on with the other emails. When it is not
set, such an email fails the whole check of the mailbox, again at each check,
and no email is read until it is removed from the folder. A skipped email stays
in the folder, unread, and no error is logged.
+ type: boolean
+ searchFrom:
+ title: Search From
+ description: Read only the emails whose sender contains this text,
such as `[email protected]`. Upper and lower case are the same. The mail
server does the search, and some servers match only a whole address, so give
the whole address to be safe.
+ type: string
+ example: [email protected]
+ pattern: "^[^\\r\\n]+$"
+ searchTo:
+ title: Search To
+ description: Read only the emails whose `To` recipients contain this
text, such as an address. The copy recipients (`Cc`) are not searched. Upper
and lower case are the same. The mail server does the search, and some servers
match only a whole address, so give the whole address to be safe.
+ type: string
+ example: [email protected]
+ pattern: "^[^\\r\\n]+$"
+ searchSubject:
+ title: Search Subject
+ description: Read only the emails whose subject contains this text,
such as `invoice`. Upper and lower case are the same.
+ type: string
+ example: invoice
+ pattern: "^[^\\r\\n]+$"
+ searchSubjectOrBody:
+ title: Search Subject or Body
+ description: Read only the emails whose subject or text contains this
text, such as `refund`. Upper and lower case are the same.
+ type: string
+ example: refund
+ pattern: "^[^\\r\\n]+$"
dataTypes:
out:
headers:
@@ -123,6 +181,20 @@ spec:
fetchSize: "{{fetchSize}}"
mail.imaps.auth.mechanisms: XOAUTH2
username: "RAW({{username}})"
+ folderName: "RAW({{?folderName}})"
+ unseen: "{{?unseen}}"
+ delete: "{{?delete}}"
+ moveTo: "RAW({{?moveTo}})"
+ copyTo: "RAW({{?copyTo}})"
+ peek: "{{?peek}}"
+ skipFailedMessage: "{{?skipFailedMessage}}"
+ # With a search, the component takes unseen from the search, so
+ # pass it there too.
+ searchTerm.unseen: "{{?unseen}}"
+ searchTerm.from: "RAW({{?searchFrom}})"
+ searchTerm.to: "RAW({{?searchTo}})"
+ searchTerm.subject: "RAW({{?searchSubject}})"
+ searchTerm.subjectOrBody: "RAW({{?searchSubjectOrBody}})"
steps:
- to:
uri: kamelet:sink
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 803ba4741..6d558777f 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
@@ -1464,8 +1464,8 @@
"type" : "source",
"supportLevel" : "Stable",
"title" : "Mail IMAP Source",
- "summary" : "Reads the unread emails in the inbox of a mailbox over IMAP,
one message per email, and marks each email as read.",
- "description" : "Reads the unread emails in the inbox of a mailbox over
IMAP, one message per email, and marks each email as read.\n\nUse it to start a
flow from incoming email, for example turn support requests into tickets, or
process the orders and invoices that customers send by email. For a Microsoft
365 mailbox that needs an OAuth login, use
`ms-exchange-online-imap-oauth-source`, and for Gmail through its API, use
`google-mail-source`.\n\nOutput: the body is the text of the em [...]
+ "summary" : "Reads the unread emails in a folder of a mailbox over IMAP,
by default the inbox, one message per email, and marks each email as read.",
+ "description" : "Reads the unread emails in a folder of a mailbox over
IMAP, by default the inbox, one message per email, and marks each email as
read.\n\nUse it to start a flow from incoming email, for example turn support
requests into tickets, or process the orders and invoices that customers send
by email. For a Microsoft 365 mailbox that needs an OAuth login, use
`ms-exchange-online-imap-oauth-source`, and for Gmail through its API, use
`google-mail-source`.\n\nOutput: the body [...]
"group" : "Mail",
"namespace" : "Mail",
"provider" : "Apache Software Foundation"
@@ -1475,7 +1475,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. It is sent as the
type in `contentType`; when that is not set, as the type in the `Content-Type`
header, such as `text/html` for an HTML email, and otherwise as plain text. The
`ce-subject`, `ce-from`, [...]
"group" : "Mail",
"namespace" : "Mail",
"provider" : "Apache Software Foundation"
@@ -1614,8 +1614,8 @@
"type" : "source",
"supportLevel" : "Stable",
"title" : "Microsoft Exchange IMAP OAuth2 Source",
- "summary" : "Reads the unread emails in the inbox of a Microsoft 365
(Exchange Online) mailbox over IMAP, logging in with OAuth 2.0, and marks each
email as read.",
- "description" : "Reads the unread emails in the inbox of a Microsoft 365
(Exchange Online) mailbox over IMAP, logging in with OAuth 2.0, and marks each
email as read.\n\nUse it to process the email that arrives in a Microsoft 365
mailbox where login with a password is turned off, for example orders, invoices
or support requests sent to a shared address. For other mail servers, use
`mail-imap-source`.\n\nOutput: the body is the text of the email. For an email
with several parts, such [...]
+ "summary" : "Reads the unread emails in a folder of a Microsoft 365
(Exchange Online) mailbox over IMAP, by default the inbox, logging in with
OAuth 2.0, and marks each email as read.",
+ "description" : "Reads the unread emails in a folder of a Microsoft 365
(Exchange Online) mailbox over IMAP, by default the inbox, logging in with
OAuth 2.0, and marks each email as read.\n\nUse it to process the email that
arrives in a Microsoft 365 mailbox where login with a password is turned off,
for example orders, invoices or support requests sent to a shared address. For
other mail servers, use `mail-imap-source`.\n\nOutput: the body is the text of
the email. For an email with [...]
"group" : "Mail",
"namespace" : "Mail",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/mail-imap-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/mail-imap-source.kamelet.yaml
index da08f5be8..5c89d1da9 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/mail-imap-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/mail-imap-source.kamelet.yaml
@@ -31,13 +31,13 @@ spec:
definition:
title: "Mail IMAP Source"
description: |-
- Reads the unread emails in the inbox of a mailbox over IMAP, one message
per email, and marks each email as read.
+ Reads the unread emails in a folder of a mailbox over IMAP, by default
the inbox, one message per email, and marks each email as read.
Use it to start a flow from incoming email, for example turn support
requests into tickets, or process the orders and invoices that customers send
by email. For a Microsoft 365 mailbox that needs an OAuth login, use
`ms-exchange-online-imap-oauth-source`, and for Gmail through its API, use
`google-mail-source`.
Output: the body is the text of the email. For an email with several
parts, such as text and HTML or attachments, it is the text of the first part;
attachments are not in the body. The `ce-subject`, `ce-from`, `ce-to` and
`ce-cc` headers hold the subject and the addresses, and the headers of the
email, such as `Subject`, `From`, `Date` and `Message-ID`, are copied too.
- Good to know: emails stay in the mailbox, marked as read, and emails
that are already read are skipped. It reads only the `INBOX` folder. It always
connects with TLS (IMAPS) and checks the certificate of the server. It checks
for new email once a minute by default (`delay`).
+ Good to know: by default it reads the `INBOX` folder, emails stay in the
folder, marked as read, and emails that are already read are skipped. Set
`delete` or `moveTo` to remove the emails once they are processed, `unseen` to
false to read the emails that are already read too, and the search options,
such as `searchFrom` or `searchSubject`, to read only some emails; an email
must match every search option that is set. An email whose processing fails
stays unread and is read again a [...]
required:
- connectionHost
- connectionPort
@@ -78,6 +78,64 @@ spec:
description: How long to wait between two checks of the mailbox, in
milliseconds. The default, 60000, is one minute.
type: integer
default: 60000
+ folderName:
+ title: Folder Name
+ description: The folder to read the emails from. When it is not set,
the Kamelet reads the `INBOX` folder. A subfolder is written with the separator
of the server, usually `/` or `.`, such as `INBOX/Orders`. When the folder does
not exist, each check of the mailbox fails with a warning in the log.
+ type: string
+ example: INBOX/Orders
+ pattern: "^[^\\r\\n%*]+$"
+ unseen:
+ title: Unread Only
+ description: Whether to read only the emails that are not marked as
read. When it is not set, only unread emails are read. When false, the emails
that are already read are read too; without `delete` or `moveTo`, every email
in the folder is then read again at each check.
+ type: boolean
+ delete:
+ title: Delete
+ description: Whether to delete each email from the folder once it is
processed. When it is not set, emails stay in the folder, marked as read. An
email whose processing fails is not deleted.
+ type: boolean
+ moveTo:
+ title: Move To
+ description: The folder to move each email to once it is processed,
such as `Processed`. The folder is created when it does not exist. The email is
then no longer in the folder that is read. An email whose processing fails is
not moved.
+ type: string
+ example: Processed
+ pattern: "^[^\\r\\n%*]+$"
+ copyTo:
+ title: Copy To
+ description: The folder to copy each email to once it is processed,
such as `Archive`. The folder is created when it does not exist. The email also
stays in the folder that is read, and the copy is not marked as read. An email
whose processing fails is not copied.
+ type: string
+ example: Archive
+ pattern: "^[^\\r\\n%*]+$"
+ peek:
+ title: Peek
+ description: Whether to keep an email unread while it is processed, so
that an email whose processing fails stays unread and is read again at the next
check. When it is not set, this is on. When false, an email is marked as read
as soon as it is read, and an email whose processing fails is not read again.
+ type: boolean
+ skipFailedMessage:
+ title: Skip Failed Email
+ description: Whether to skip an email that cannot be read at all, such
as one with a broken format, and go on with the other emails. When it is not
set, such an email fails the whole check of the mailbox, again at each check,
and no email is read until it is removed from the folder. A skipped email stays
in the folder, unread, and no error is logged.
+ type: boolean
+ searchFrom:
+ title: Search From
+ description: Read only the emails whose sender contains this text,
such as `[email protected]`. Upper and lower case are the same. The mail
server does the search, and some servers match only a whole address, so give
the whole address to be safe.
+ type: string
+ example: [email protected]
+ pattern: "^[^\\r\\n]+$"
+ searchTo:
+ title: Search To
+ description: Read only the emails whose `To` recipients contain this
text, such as an address. The copy recipients (`Cc`) are not searched. Upper
and lower case are the same. The mail server does the search, and some servers
match only a whole address, so give the whole address to be safe.
+ type: string
+ example: [email protected]
+ pattern: "^[^\\r\\n]+$"
+ searchSubject:
+ title: Search Subject
+ description: Read only the emails whose subject contains this text,
such as `invoice`. Upper and lower case are the same.
+ type: string
+ example: invoice
+ pattern: "^[^\\r\\n]+$"
+ searchSubjectOrBody:
+ title: Search Subject or Body
+ description: Read only the emails whose subject or text contains this
text, such as `refund`. Upper and lower case are the same.
+ type: string
+ example: refund
+ pattern: "^[^\\r\\n]+$"
dataTypes:
out:
headers:
@@ -110,6 +168,20 @@ spec:
fetchSize: "{{fetchSize}}"
password: "RAW({{password}})"
username: "RAW({{username}})"
+ folderName: "RAW({{?folderName}})"
+ unseen: "{{?unseen}}"
+ delete: "{{?delete}}"
+ moveTo: "RAW({{?moveTo}})"
+ copyTo: "RAW({{?copyTo}})"
+ peek: "{{?peek}}"
+ skipFailedMessage: "{{?skipFailedMessage}}"
+ # With a search, the component takes unseen from the search, so
+ # pass it there too.
+ searchTerm.unseen: "{{?unseen}}"
+ searchTerm.from: "RAW({{?searchFrom}})"
+ searchTerm.to: "RAW({{?searchTo}})"
+ searchTerm.subject: "RAW({{?searchSubject}})"
+ searchTerm.subjectOrBody: "RAW({{?searchSubjectOrBody}})"
steps:
- setHeader:
name: ce-subject
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 64624cedb..33696c430 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
@@ -35,11 +35,11 @@ spec:
Use it to send notifications, alerts or reports by email, for example
tell a team when an order fails or send a daily summary.
- Input: 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 one email, in place of the options; several addresses are
separated by commas. Other mail headers on the message, such as `To` or `Bcc`,
are removed and not used.
+ Input: the body is the text of the email. It is sent as the type in
`contentType`; when that is not set, as the type in the `Content-Type` header,
such as `text/html` for an HTML email, and otherwise as plain text. The
`ce-subject`, `ce-from`, `ce-to` and `ce-cc` headers set the subject, the
sender, the recipients and the copy recipients of one email, each in place of
its option; several addresses are separated by commas. Other mail headers on
the message, such as `To`, `Bcc` or `R [...]
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 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 [...]
+ 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
@@ -94,6 +94,28 @@ spec:
example: Order failed
title: Subject
type: string
+ cc:
+ title: Cc
+ description: The copy recipients of the emails; several addresses are
separated by commas. The `ce-cc` header replaces it for one message.
+ example: [email protected]
+ type: string
+ bcc:
+ title: Bcc
+ description: The blind copy recipients of the emails; several
addresses are separated by commas. They receive each email, and the other
recipients do not see them. Messages cannot change them.
+ example: [email protected]
+ type: string
+ replyTo:
+ title: Reply To
+ description: The address that replies to the emails go to, in place of
the sender; several addresses are separated by commas. Messages cannot change
it.
+ example: [email protected]
+ type: string
+ pattern: "^[^\\r\\n]*@[^\\r\\n]*$"
+ contentType:
+ title: Content Type
+ description: The type of the text in the body of every email, such as
`text/html` to send HTML emails. When it is set, the `Content-Type` header of
the message is not used. When it is not set, that header sets the type, and
without it the emails are sent as plain text (`text/plain`). Some sources set
that header, such as `timer-source`, which sets `text/plain` by default.
+ example: text/html
+ type: string
+ pattern: "^[A-Za-z0-9.+-]+/[A-Za-z0-9.+-]+(\\s*;.*)?$"
dataTypes:
in:
headers:
@@ -111,11 +133,11 @@ spec:
type: string
ce-cc:
title: Cc
- description: The copy recipients of the email, separated by commas.
+ description: The copy recipients of the email, separated by commas,
in place of the `cc` option.
type: string
Content-Type:
title: Content Type
- description: The type of the text in the body, such as `text/html`
to send an HTML email.
+ description: The type of the text in the body, such as `text/html`
to send an HTML email. Not used when the `contentType` option is set.
type: string
out:
headers:
@@ -167,6 +189,10 @@ spec:
expression:
simple:
expression: "${header[ce-from]}"
+ # The mail component takes the recipients either all from the To,
+ # Cc and Bcc headers or, when there is none, all from the to, cc and
+ # bcc options. Put the options into the headers, so that a ce-to or
+ # ce-cc header replaces only its own option, and bcc is always kept.
- choice:
when:
- expression:
@@ -178,6 +204,15 @@ spec:
expression:
simple:
expression: "${header[ce-to]}"
+ - expression:
+ constant:
+ expression: "{{?to}}"
+ steps:
+ - setHeader:
+ name: To
+ expression:
+ constant:
+ expression: "{{?to}}"
- choice:
when:
- expression:
@@ -189,10 +224,43 @@ spec:
expression:
simple:
expression: "${header[ce-cc]}"
+ - expression:
+ constant:
+ expression: "{{?cc}}"
+ steps:
+ - setHeader:
+ name: Cc
+ expression:
+ constant:
+ expression: "{{?cc}}"
+ - choice:
+ when:
+ - expression:
+ constant:
+ expression: "{{?bcc}}"
+ steps:
+ - setHeader:
+ name: Bcc
+ expression:
+ constant:
+ expression: "{{?bcc}}"
+ # A contentType option is the type of every email: a Content-Type
+ # header from an earlier step, such as the text/plain one of
+ # timer-source, must not replace it.
+ - choice:
+ when:
+ - expression:
+ constant:
+ expression: "{{?contentType}}"
+ steps:
+ - removeHeader:
+ name: Content-Type
+ - removeHeader:
+ name: CamelMailContentType
- removeHeaders:
pattern: ce-*
- to:
- 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}}"
+ 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}}&replyTo=RAW({{?replyTo}})&contentType=RAW({{?contentType}})"
# 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
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/ms-exchange-online-imap-oauth-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/ms-exchange-online-imap-oauth-source.kamelet.yaml
index 1782de5eb..d1d6e291d 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/ms-exchange-online-imap-oauth-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/ms-exchange-online-imap-oauth-source.kamelet.yaml
@@ -31,13 +31,13 @@ spec:
definition:
title: "Microsoft Exchange IMAP OAuth2 Source"
description: |-
- Reads the unread emails in the inbox of a Microsoft 365 (Exchange
Online) mailbox over IMAP, logging in with OAuth 2.0, and marks each email as
read.
+ Reads the unread emails in a folder of a Microsoft 365 (Exchange Online)
mailbox over IMAP, by default the inbox, logging in with OAuth 2.0, and marks
each email as read.
Use it to process the email that arrives in a Microsoft 365 mailbox
where login with a password is turned off, for example orders, invoices or
support requests sent to a shared address. For other mail servers, use
`mail-imap-source`.
Output: the body is the text of the email. For an email with several
parts, such as text and HTML or attachments, it is the content of the parts,
which the next step reads as the text of the first part. The headers of the
email, such as `Subject`, `From`, `To` and `Date`, are copied to the message.
- Good to know: it logs in as an application, not as a person: register an
application in Microsoft Entra ID (formerly Azure Active Directory) with a
client secret, and allow it to read the mailbox over IMAP. It gets a token when
it starts, so with wrong credentials, such as an unknown tenant ID, the
integration does not start. Emails stay in the mailbox, marked as read, and
emails that are already read are skipped. It reads only the `INBOX` folder,
over TLS, and checks for new email [...]
+ Good to know: it logs in as an application, not as a person: register an
application in Microsoft Entra ID (formerly Azure Active Directory) with a
client secret, and allow it to read the mailbox over IMAP. It gets a token when
it starts, so with wrong credentials, such as an unknown tenant ID, the
integration does not start. By default it reads the `INBOX` folder, emails stay
in the folder, marked as read, and emails that are already read are skipped.
Set `delete` or `moveTo` to r [...]
required:
- tenantId
- clientId
@@ -90,6 +90,64 @@ spec:
description: How long to wait between two checks of the mailbox, in
milliseconds. The default, 60000, is one minute.
type: integer
default: 60000
+ folderName:
+ title: Folder Name
+ description: The folder to read the emails from. When it is not set,
the Kamelet reads the `INBOX` folder. A subfolder is written with the separator
of the server, usually `/` or `.`, such as `INBOX/Orders`. When the folder does
not exist, each check of the mailbox fails with a warning in the log.
+ type: string
+ example: INBOX/Orders
+ pattern: "^[^\\r\\n%*]+$"
+ unseen:
+ title: Unread Only
+ description: Whether to read only the emails that are not marked as
read. When it is not set, only unread emails are read. When false, the emails
that are already read are read too; without `delete` or `moveTo`, every email
in the folder is then read again at each check.
+ type: boolean
+ delete:
+ title: Delete
+ description: Whether to delete each email from the folder once it is
processed. When it is not set, emails stay in the folder, marked as read. An
email whose processing fails is not deleted.
+ type: boolean
+ moveTo:
+ title: Move To
+ description: The folder to move each email to once it is processed,
such as `Processed`. The folder is created when it does not exist. The email is
then no longer in the folder that is read. An email whose processing fails is
not moved.
+ type: string
+ example: Processed
+ pattern: "^[^\\r\\n%*]+$"
+ copyTo:
+ title: Copy To
+ description: The folder to copy each email to once it is processed,
such as `Archive`. The folder is created when it does not exist. The email also
stays in the folder that is read, and the copy is not marked as read. An email
whose processing fails is not copied.
+ type: string
+ example: Archive
+ pattern: "^[^\\r\\n%*]+$"
+ peek:
+ title: Peek
+ description: Whether to keep an email unread while it is processed, so
that an email whose processing fails stays unread and is read again at the next
check. When it is not set, this is on. When false, an email is marked as read
as soon as it is read, and an email whose processing fails is not read again.
+ type: boolean
+ skipFailedMessage:
+ title: Skip Failed Email
+ description: Whether to skip an email that cannot be read at all, such
as one with a broken format, and go on with the other emails. When it is not
set, such an email fails the whole check of the mailbox, again at each check,
and no email is read until it is removed from the folder. A skipped email stays
in the folder, unread, and no error is logged.
+ type: boolean
+ searchFrom:
+ title: Search From
+ description: Read only the emails whose sender contains this text,
such as `[email protected]`. Upper and lower case are the same. The mail
server does the search, and some servers match only a whole address, so give
the whole address to be safe.
+ type: string
+ example: [email protected]
+ pattern: "^[^\\r\\n]+$"
+ searchTo:
+ title: Search To
+ description: Read only the emails whose `To` recipients contain this
text, such as an address. The copy recipients (`Cc`) are not searched. Upper
and lower case are the same. The mail server does the search, and some servers
match only a whole address, so give the whole address to be safe.
+ type: string
+ example: [email protected]
+ pattern: "^[^\\r\\n]+$"
+ searchSubject:
+ title: Search Subject
+ description: Read only the emails whose subject contains this text,
such as `invoice`. Upper and lower case are the same.
+ type: string
+ example: invoice
+ pattern: "^[^\\r\\n]+$"
+ searchSubjectOrBody:
+ title: Search Subject or Body
+ description: Read only the emails whose subject or text contains this
text, such as `refund`. Upper and lower case are the same.
+ type: string
+ example: refund
+ pattern: "^[^\\r\\n]+$"
dataTypes:
out:
headers:
@@ -123,6 +181,20 @@ spec:
fetchSize: "{{fetchSize}}"
mail.imaps.auth.mechanisms: XOAUTH2
username: "RAW({{username}})"
+ folderName: "RAW({{?folderName}})"
+ unseen: "{{?unseen}}"
+ delete: "{{?delete}}"
+ moveTo: "RAW({{?moveTo}})"
+ copyTo: "RAW({{?copyTo}})"
+ peek: "{{?peek}}"
+ skipFailedMessage: "{{?skipFailedMessage}}"
+ # With a search, the component takes unseen from the search, so
+ # pass it there too.
+ searchTerm.unseen: "{{?unseen}}"
+ searchTerm.from: "RAW({{?searchFrom}})"
+ searchTerm.to: "RAW({{?searchTo}})"
+ searchTerm.subject: "RAW({{?searchSubject}})"
+ searchTerm.subjectOrBody: "RAW({{?searchSubjectOrBody}})"
steps:
- to:
uri: kamelet:sink
diff --git
a/tests/camel-kamelets-itest/src/test/resources/mail/mail-sink-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/mail/mail-sink-route.citrus.it.yaml
index 5b7f5a628..50f682f97 100644
---
a/tests/camel-kamelets-itest/src/test/resources/mail/mail-sink-route.citrus.it.yaml
+++
b/tests/camel-kamelets-itest/src/test/resources/mail/mail-sink-route.citrus.it.yaml
@@ -31,6 +31,12 @@ variables:
value: "[email protected]"
- name: "mail.subject"
value: "Kamelet workshop"
+ - name: "mail.cc"
+ value: "[email protected]"
+ - name: "mail.bcc"
+ value: "[email protected]"
+ - name: "mail.replyTo"
+ value: "[email protected]"
- name: "mail.message"
value: "Camel rocks!"
actions:
@@ -54,20 +60,30 @@ actions:
value: "${mail.to}"
- name: "mail.subject"
value: "${mail.subject}"
+ - name: "mail.cc"
+ value: "${mail.cc}"
+ - name: "mail.bcc"
+ value: "${mail.bcc}"
+ - name: "mail.replyTo"
+ value: "${mail.replyTo}"
- name: "mail.message"
value: "${mail.message}"
# Verify mail event
- receive:
endpoint: mailServer
message:
+ headers:
+ - name: "citrus_mail_reply_to"
+ value: "${mail.replyTo}"
body:
data: |
{
"from": "${mail.from}",
"to": "${mail.to}",
+ "cc": "${mail.cc}",
"subject": "${mail.subject}",
"body": {
- "contentType": "@startsWith('text/plain')@",
+ "contentType": "@startsWith('text/html')@",
"content": "${mail.message}",
}
}
diff --git
a/tests/camel-kamelets-itest/src/test/resources/mail/mail-sink-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/mail/mail-sink-route.yaml
index 9f7903508..b283b9144 100644
--- a/tests/camel-kamelets-itest/src/test/resources/mail/mail-sink-route.yaml
+++ b/tests/camel-kamelets-itest/src/test/resources/mail/mail-sink-route.yaml
@@ -32,3 +32,7 @@
from: '{{mail.from}}'
to: '{{mail.to}}'
subject: '{{mail.subject}}'
+ cc: '{{mail.cc}}'
+ bcc: '{{mail.bcc}}'
+ replyTo: '{{mail.replyTo}}'
+ contentType: text/html