Camel Spring Boot

IMAP

Send emails with SMTP and receive emails by polling a mailbox with IMAP or POP3.

What’s inside

Please refer to the above links for usage and configuration details.

Maven coordinates

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-mail-starter</artifactId>
</dependency>

Spring Boot Auto-Configuration

The starter supports 61 options, which are listed below.

Name Description Default Type

camel.component.mail.additional-java-mail-properties

Jakarta Mail session properties to add to the ones Camel sets from the other options, replacing them on the same key, for example mail.smtp.starttls.enable=true. In the endpoint URI, each option whose name starts with mail. is such a property. Ignored when javaMailProperties or session is set. This is a multi-value option with prefix: mail. The option is a java.util.Properties type.

Properties

camel.component.mail.alternative-body-header

The name of the message header that holds the plain text alternative of the body. When the message has this header, the producer sends a multipart/alternative mail with that text and the body (in contentType, typically text/html) as its two parts, and removes the header.

CamelMailAlternativeBody

String

camel.component.mail.attachments-content-transfer-encoding-resolver

A resolver that sets the Content-Transfer-Encoding (for example base64) of each attachment the producer adds. When it returns null, Jakarta Mail chooses the encoding. The option is a org.apache.camel.component.mail.AttachmentsContentTransferEncodingResolver type.

AttachmentsContentTransferEncodingResolver

camel.component.mail.authenticator

A MailAuthenticator (a jakarta.mail.Authenticator) that supplies the user name and password each time Camel connects, instead of the username and password options. Use it for credentials that change, such as OAuth2 access tokens that expire. The option is a org.apache.camel.component.mail.MailAuthenticator type.

MailAuthenticator

camel.component.mail.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.mail.bcc

The Bcc recipients of the mails the producer sends, separated by comma or semicolon. Ignored when useHeaderRecipients=true and the message has a To, Cc or Bcc header.

String

camel.component.mail.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.mail.cc

The Cc recipients of the mails the producer sends, separated by comma or semicolon. Ignored when useHeaderRecipients=true and the message has a To, Cc or Bcc header.

String

camel.component.mail.close-folder

Whether the consumer closes the folder after each poll. Closing expunges the mails flagged DELETED (by delete or moveTo). With closeFolder=false and disconnect=false the folder stays open between polls, and deleted mails are removed only when the folder is closed, at the latest when the consumer stops. Keep it true for POP3: a POP3 folder that stays open does not see new mails.

true

Boolean

camel.component.mail.configuration

A MailConfiguration whose options are the defaults of every endpoint of the component (each endpoint uses a copy of it). The option is a org.apache.camel.component.mail.MailConfiguration type.

MailConfiguration

camel.component.mail.connection-timeout

The timeout in milliseconds for connecting to the mail server and for reading from the connection: Camel sets it as the connectiontimeout and timeout properties of the protocol in the Jakarta Mail session (for example mail.imaps.connectiontimeout and mail.imaps.timeout). 0 or a negative value means no timeout. Not applied when javaMailProperties or session is set.

30000

Integer

camel.component.mail.content-type

The Content-Type of the mail body the producer sends, for example text/html for an HTML mail. The contentType or Content-Type header of the message overrides it. When a text type has no charset, the charset of the exchange, else the default charset of Jakarta Mail, is added.

text/plain

String

camel.component.mail.content-type-resolver

A resolver that sets the Content-Type of each attachment the producer adds, from its file name. When it returns null, the content type of the DataHandler of the attachment is used. The option is a org.apache.camel.component.mail.ContentTypeResolver type.

ContentTypeResolver

camel.component.mail.copy-to

The IMAP folder to copy a mail to once its exchange completed successfully. The folder is created if it does not exist. The CamelMailCopyTo header overrides this option for a mail. Ignored for POP3.

String

camel.component.mail.debug-mode

Whether to turn on the debug output of Jakarta Mail (Session.setDebug), which prints the protocol commands and responses to System.out. Not applied when a session is set.

false

Boolean

camel.component.mail.decode-filename

Whether the consumer decodes MIME encoded file names of attachments with MimeUtility.decodeText. This is like setting the system property mail.mime.decodefilename=true.

false

Boolean

camel.component.mail.delete

Whether the consumer deletes a mail once its exchange completed successfully: it sets the DELETED flag on the mail instead of the SEEN flag, and the mail is removed from the server when the folder is closed (see closeFolder). The CamelMailDelete header overrides this option for a mail. POP3 keeps no SEEN flag on the server, so with POP3 deleting is how a consumed mail is not consumed again.

false

Boolean

camel.component.mail.disconnect

Whether the consumer closes the folder and disconnects from the mail server (Store.close) after each poll, so that every poll connects again. By default the connection stays open between polls.

false

Boolean

camel.component.mail.enabled

Whether to enable auto configuration of the mail component. This is enabled by default.

Boolean

camel.component.mail.fail-on-duplicate-file-attachment

Whether to fail processing the mail if the mail message contains attachments with duplicate file names. If set to false, then the duplicate attachment is skipped and a WARN is logged. If set to true, then an exception is thrown failing to process the mail message.

false

Boolean

camel.component.mail.fetch-size

The maximum number of mails the consumer consumes per poll, which avoids loading the mail server when a folder holds many mails. -1 (default) sets no limit here, so maxMessagesPerPoll applies. 0 skips every poll, so no mail is consumed. A value of 0 or more takes precedence over maxMessagesPerPoll.

-1

Integer

camel.component.mail.folder-name

The name of the folder the consumer polls. With POP3, only INBOX exists.

INBOX

String

camel.component.mail.from

The From address of the mails the producer sends. The From header of the message is ignored unless useHeaderFrom=true.

camel@localhost

String

camel.component.mail.generate-missing-attachment-names

How the consumer names an attachment (a part with the Content-Disposition attachment or inline) that has no file name: never (default) leaves it without a name, so it is not extracted as an attachment; uuid names it with a random UUID.

String

camel.component.mail.handle-duplicate-attachment-names

How the consumer handles attachments of a mail that have the same file name: never (default) keeps the first one and skips the others, or fails with failOnDuplicateFileAttachment=true; uuidPrefix renames them to uuid_filename.ext; uuidSuffix renames them to filename_uuid.ext.

String

camel.component.mail.handle-failed-message

Whether the consumer passes the exception of a mail that it cannot retrieve or map to an exchange to its exception handler (which logs it at WARN, or with bridgeErrorHandler=true routes it to the error handler of the route), and goes on with the next mail. When neither this option nor skipFailedMessage is set, the poll fails and none of its mails is routed.

false

Boolean

camel.component.mail.header-filter-strategy

A HeaderFilterStrategy for every endpoint of the component, instead of the default MailHeaderFilterStrategy. It decides which headers of the Camel message the producer copies into the mail, and which headers of the mail the consumer maps to Camel headers. The option is a org.apache.camel.spi.HeaderFilterStrategy type.

HeaderFilterStrategy

camel.component.mail.health-check-consumer-enabled

Used for enabling or disabling all consumer based health checks from this component

true

Boolean

camel.component.mail.health-check-producer-enabled

Used for enabling or disabling all producer based health checks from this component. Notice: Camel has by default disabled all producer based health-checks. You can turn on producer checks globally by setting camel.health.producersEnabled=true.

true

Boolean

camel.component.mail.ignore-unsupported-charset

Whether the producer removes a charset that the JVM does not support from the Content-Type (logging a WARN) instead of failing to send the mail. A text body then gets the default charset of Jakarta Mail.

false

Boolean

camel.component.mail.ignore-uri-scheme

Whether to ignore the scheme of the endpoint URI when configuring the mail protocol. By default the scheme (imap, imaps, pop3, pop3s, smtp or smtps) sets the protocol used to talk to the mail server. Enable this to keep a protocol that was already configured on the mail configuration, for example one shared via the component.

false

Boolean

camel.component.mail.java-mail-properties

The Jakarta Mail session properties to use instead of the ones Camel creates: Camel then adds neither the JVM system properties nor the properties it sets from the other options (host, port, auth, connectionTimeout, sslContextParameters), and ignores additionalJavaMailProperties. Not applied when session is set. The option is a java.util.Properties type.

Properties

camel.component.mail.java-mail-sender

A custom JavaMailSender that the producer sends the mails with. Camel sets the host, port, username, password, authenticator, protocol and Jakarta Mail session on it where it has none. The default DefaultJavaMailSender connects a Transport for each mail it sends. The consumer does not use it. The option is a org.apache.camel.component.mail.JavaMailSender type.

JavaMailSender

camel.component.mail.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.mail.map-mail-message

Whether the consumer maps the mail to the Camel message: the content of the mail becomes the body (a String for a text mail, a Multipart for a multipart mail) and the attachments become Camel attachments, all read from the server when the mail is polled. When false, the body is the jakarta.mail.Message itself, no attachments are extracted, and the content is read only when the route reads it. In both cases the mail headers become Camel headers.

true

Boolean

camel.component.mail.max-multipart-depth

The maximum nesting depth of multipart MIME parts the consumer descends into when extracting attachments. A message nested deeper than this has its deeper parts skipped, so a crafted deeply nested multipart cannot exhaust the stack. Increase it only if a legitimate source produces unusually deep nesting.

20

Integer

camel.component.mail.mime-decode-headers

Whether the consumer unfolds the mail header values and decodes their MIME encoded words (MimeUtility.decodeText, for example =?UTF-8?B?…​?=) before it maps them to Camel headers.

false

Boolean

camel.component.mail.move-to

The IMAP folder to move a mail to once its exchange completed successfully: the mail is copied to that folder and flagged DELETED in the polled folder, from which it is removed when the folder is closed (see closeFolder). The folder is created if it does not exist. The CamelMailMoveTo header overrides this option for a mail. Ignored for POP3.

String

camel.component.mail.password

The password to log in to the mail server. Ignored when an authenticator is set.

String

camel.component.mail.peek

Whether the consumer sets peek on each IMAP mail (IMAPMessage.setPeek) before reading it, so reading the mail does not set the SEEN flag on the server. The consumer then sets SEEN (or DELETED) only once the exchange completed successfully, so a mail whose exchange failed stays unseen and a later poll consumes it again. With peek=false the server sets SEEN when the content is read, which with mapMailMessage=true happens for every mail of a poll when it is retrieved: a mail that fails or is not routed (the consumer stops, or an earlier mail of the poll failed) is then not polled again with unseen=true. IMAP only.

true

Boolean

camel.component.mail.reply-to

The Reply-To addresses of the mails the producer sends, separated by comma or semicolon. The Reply-To header of the message is ignored unless useHeaderReplyTo=true.

String

camel.component.mail.session

A jakarta.mail.Session to use instead of the one Camel creates, for example a session managed by an application server. Camel then does not apply javaMailProperties, additionalJavaMailProperties, connectionTimeout, sslContextParameters and debugMode, and the producer takes the host and port from the mail.smtp.host (or mail.smtps.host) and mail.smtp.port (or mail.smtps.port) properties of the session when they are set. The username and password options are still used to connect. The option is a jakarta.mail.Session type.

Session

camel.component.mail.skip-failed-message

Whether the consumer skips a mail that it cannot retrieve or map to an exchange (for example a malformed mail), logging it at DEBUG, and goes on with the next mail. When neither this option nor handleFailedMessage is set, the poll fails and none of its mails is routed. Takes precedence over handleFailedMessage.

false

Boolean

camel.component.mail.ssl-context-parameters

The SSL/TLS configuration (key store, trust store, protocols) of the connection to the mail server. Used for imaps, pop3s and smtps, and for imap, pop3 and smtp when STARTTLS is turned on in additionalJavaMailProperties, for example with mail.smtp.starttls.enable=true or mail.smtp.starttls.required=true (mail.imap. or mail.pop3. for the others). Not applied when javaMailProperties or session is set. Without it, the default SSL socket factory of the JVM is used. The option is a org.apache.camel.support.jsse.SSLContextParameters type.

SSLContextParameters

camel.component.mail.subject

The Subject of the message being sent. The Subject message header is ignored unless useHeaderSubject=true, in which case it overrides this option.

String

camel.component.mail.to

The To recipients of the mails the producer sends, separated by comma or semicolon. Ignored when useHeaderRecipients=true and the message has a To, Cc or Bcc header.

String

camel.component.mail.unseen

Whether the consumer polls only the mails that do not have the SEEN flag. Ignored when a searchTerm is set. POP3 keeps no flags on the server, so every mail counts as unseen each time the folder is opened: use delete=true, or an idempotentRepository with idempotentRepositoryRemoveOnCommit=false, to not consume a mail again.

true

Boolean

camel.component.mail.use-global-ssl-context-parameters

Enable usage of global SSL context parameters.

false

Boolean

camel.component.mail.use-header-from

Whether the From and Sender headers of the message set the From and Sender of the mail, overriding the from option. When false (default), both headers are ignored.

false

Boolean

camel.component.mail.use-header-recipients

Whether the To, Cc and Bcc headers of the message set the recipients of the mail. When true and the message has any of these headers, the mail goes only to the addresses in the headers, and the to, cc and bcc options are ignored. When false (default), these headers are ignored and not copied into the mail.

false

Boolean

camel.component.mail.use-header-reply-to

Whether the Reply-To header of the message sets the Reply-To of the mail, overriding the replyTo option. When false (default), the header is ignored.

false

Boolean

camel.component.mail.use-header-subject

Whether the Subject header of the message sets the subject of the mail, overriding the subject option. When false (default), the header is ignored.

false

Boolean

camel.component.mail.use-inline-attachments

Whether the producer adds the attachments of the message with the Content-Disposition inline instead of attachment. With an alternative body (see alternativeBodyHeader), the inline attachments go with the body into a multipart/related part, so an HTML body can refer to them by Content-ID: an attachment whose name starts with cid: gets the rest of the name as Content-ID.

false

Boolean

camel.component.mail.use-java-mail-session-properties-from-headers

Whether to allow dynamic JavaMail session properties (message headers whose key starts with mail.smtp. or mail.smtps.) to override the endpoint configuration on a per-message basis. This is disabled by default. Only enable it when these headers originate exclusively from trusted route logic, never from data crossing a trust boundary (for example HTTP query parameters, or JMS/Kafka messages from untrusted producers). When enabled, an attacker able to set these headers could weaken transport security (such as mail.smtp.ssl.trust or mail.smtp.starttls.enable) or redirect the SMTP connection.

false

Boolean

camel.component.mail.username

The user name to log in to the mail server. It is not used for the login when an authenticator is set. For the producer, when no to, cc or bcc recipient is configured yet, it also sets the to option to this user name, adding an at sign and the host when the user name has no at sign.

String

camel.dataformat.mime-multipart.binary-content

Whether the content of binary parts in the MIME multipart is binary (true) or Base-64 encoded (false).

false

Boolean

camel.dataformat.mime-multipart.enabled

Whether to enable auto configuration of the mimeMultipart data format. This is enabled by default.

Boolean

camel.dataformat.mime-multipart.headers-inline

Whether the MIME-Multipart headers are part of the message body (true) or are set as Camel headers (false).

false

Boolean

camel.dataformat.mime-multipart.include-headers

A regex that defines which Camel headers are also included as MIME headers into the MIME multipart. This only works if headersInline is set to true.

String

camel.dataformat.mime-multipart.multipart-sub-type

Specify the subtype of the MIME Multipart.

mixed

String

camel.dataformat.mime-multipart.multipart-without-attachment

Whether a message without attachment is also marshaled into a MIME Multipart (with only one body part).

false

Boolean