---
apiVersion: v1
kind: ConfigMap
metadata:
  labels:
    funktion.fabric8.io/kind: Connector
  name: smtps
data:
  deployment.yml: |
    ---
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      labels:
        funktion.fabric8.io/kind: Subscription
        connector: smtps
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            funktion.fabric8.io/kind: Subscription
            connector: smtps
        spec:
          containers:
          - image: funktion/connector-smtps:${project.version}
            name: connector
  schema.yml: |
    ---
    component:
      kind: component
      scheme: smtps
      alternativeSchemes: imap,imaps,pop3,pop3s,smtp,smtps
      syntax: smtps:host:port
      alternativeSyntax: smtps:username:password@host:port
      title: SMTPS
      description: To send or receive emails using imap/pop3 or stmp protocols.
      label: mail
      deprecated: false
      async: false
      javaType: org.apache.camel.component.mail.MailComponent
      groupId: org.apache.camel
      artifactId: camel-mail
      version: 2.18.3
    componentProperties:
      configuration:
        kind: property
        type: object
        javaType: org.apache.camel.component.mail.MailConfiguration
        deprecated: false
        secret: false
        description: Sets the Mail configuration
        order: 0
      contentTypeResolver:
        kind: property
        type: object
        javaType: org.apache.camel.component.mail.ContentTypeResolver
        deprecated: false
        secret: false
        description: Resolver to determine Content-Type for file attachments.
        order: 1
    properties:
      host:
        kind: path
        group: common
        required: true
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: The mail server host name
        order: 0
      port:
        kind: path
        group: common
        type: integer
        javaType: int
        deprecated: false
        secret: false
        description: The port number of the mail server
        order: 1
      bridgeErrorHandler:
        kind: parameter
        group: consumer
        label: consumer
        type: boolean
        javaType: boolean
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: false
        description: Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
        order: 2
      closeFolder:
        kind: parameter
        group: consumer
        label: consumer
        required: false
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: true
        description: Whether the consumer should close the folder after polling. Setting this option to false and having disconnect=false as well then the consumer keep the folder open between polls.
        order: 3
      copyTo:
        kind: parameter
        group: consumer
        label: consumer
        required: false
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: After processing a mail message it can be copied to a mail folder with the given name. You can override this configuration value with a header with the key copyTo allowing you to copy messages to folder names configured at runtime.
        order: 4
      delete:
        kind: parameter
        group: consumer
        label: consumer
        required: false
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Deletes the messages after they have been processed. This is done by setting the DELETED flag on the mail message. If false the SEEN flag is set instead. As of Camel 2.10 you can override this configuration option by setting a header with the key delete to determine if the mail should be deleted or not.
        order: 5
      disconnect:
        kind: parameter
        group: consumer
        label: consumer
        required: false
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Whether the consumer should disconnect after polling. If enabled this forces Camel to connect on each poll.
        order: 6
      handleFailedMessage:
        kind: parameter
        group: consumer
        label: consumer
        required: false
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: If the mail consumer cannot retrieve a given mail message then this option allows to handle the caused exception by the consumer's error handler. By enable the bridge error handler on the consumer then the Camel routing error handler can handle the exception instead. The default behavior would be the consumer throws an exception and no mails from the batch would be able to be routed by Camel.
        order: 7
      maxMessagesPerPoll:
        kind: parameter
        group: consumer
        label: consumer
        type: integer
        javaType: int
        deprecated: false
        secret: false
        description: Specifies the maximum number of messages to gather per poll. By default no maximum is set. Can be used to set a limit of e.g. 1000 to avoid downloading thousands of files when the server starts up. Set a value of 0 or negative to disable this option.
        order: 8
      peek:
        kind: parameter
        group: consumer
        label: consumer
        required: false
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: true
        description: Will mark the javax.mail.Message as peeked before processing the mail message. This applies to IMAPMessage messages types only. By using peek the mail will not be eager marked as SEEN on the mail server which allows us to rollback the mail message if there is an error processing in Camel.
        order: 9
      sendEmptyMessageWhenIdle:
        kind: parameter
        group: consumer
        label: consumer
        type: boolean
        javaType: boolean
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: false
        description: If the polling consumer did not poll any files you can enable this option to send an empty message (no body) instead.
        order: 10
      skipFailedMessage:
        kind: parameter
        group: consumer
        label: consumer
        required: false
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: If the mail consumer cannot retrieve a given mail message then this option allows to skip the message and move on to retrieve the next mail message. The default behavior would be the consumer throws an exception and no mails from the batch would be able to be routed by Camel.
        order: 11
      unseen:
        kind: parameter
        group: consumer
        label: consumer
        required: false
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: true
        description: Whether to limit by unseen mails only.
        order: 12
      exceptionHandler:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: object
        javaType: org.apache.camel.spi.ExceptionHandler
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        description: To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
        order: 13
      exchangePattern:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: string
        javaType: org.apache.camel.ExchangePattern
        enum:
        - InOnly
        - RobustInOnly
        - InOut
        - InOptionalOut
        - OutOnly
        - RobustOutOnly
        - OutIn
        - OutOptionalIn
        deprecated: false
        secret: false
        description: Sets the exchange pattern when the consumer creates an exchange.
        order: 14
      fetchSize:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        required: false
        type: integer
        javaType: int
        deprecated: false
        secret: false
        defaultValue: -1
        description: Sets the maximum number of messages to consume during a poll. This can be used to avoid overloading a mail server if a mailbox folder contains a lot of messages. Default value of -1 means no fetch size and all messages will be consumed. Setting the value to 0 is a special corner case where Camel will not consume any messages at all.
        order: 15
      folderName:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        defaultValue: INBOX
        description: The folder to poll.
        order: 16
      mailUidGenerator:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: object
        javaType: org.apache.camel.component.mail.MailUidGenerator
        deprecated: false
        secret: false
        description: A pluggable MailUidGenerator that allows to use custom logic to generate UUID of the mail message.
        order: 17
      mapMailMessage:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: true
        description: Specifies whether Camel should map the received mail message to Camel body/headers. If set to true the body of the mail message is mapped to the body of the Camel IN message and the mail headers are mapped to IN headers. If this option is set to false then the IN message contains a raw javax.mail.Message. You can retrieve this raw message by calling exchange.getIn().getBody(javax.mail.Message.class).
        order: 18
      pollStrategy:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: object
        javaType: org.apache.camel.spi.PollingConsumerPollStrategy
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        description: A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.
        order: 19
      postProcessAction:
        kind: parameter
        group: consumer (advanced)
        label: consumer,advanced
        type: object
        javaType: org.apache.camel.component.mail.MailBoxPostProcessAction
        deprecated: false
        secret: false
        description: Refers to an MailBoxPostProcessAction for doing post processing tasks on the mailbox once the normal processing ended.
        order: 20
      bcc:
        kind: parameter
        group: producer
        label: producer
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Sets the BCC email address. Separate multiple email addresses with comma.
        order: 21
      cc:
        kind: parameter
        group: producer
        label: producer
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Sets the CC email address. Separate multiple email addresses with comma.
        order: 22
      from:
        kind: parameter
        group: producer
        label: producer
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        defaultValue: camel@localhost
        description: The from email address
        order: 23
      replyTo:
        kind: parameter
        group: producer
        label: producer
        required: false
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: The Reply-To recipients (the receivers of the response mail). Separate multiple email addresses with a comma.
        order: 24
      subject:
        kind: parameter
        group: producer
        label: producer
        required: false
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: 'The Subject of the message being sent. Note: Setting the subject
          in the header takes precedence over this option.'
        order: 25
      to:
        kind: parameter
        group: producer
        label: producer
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Sets the To email address. Separate multiple email addresses with comma.
        order: 26
      javaMailSender:
        kind: parameter
        group: producer (advanced)
        label: producer,advanced
        required: false
        type: object
        javaType: org.apache.camel.component.mail.JavaMailSender
        deprecated: false
        secret: false
        description: To use a custom org.apache.camel.component.mail.JavaMailSender for sending emails.
        order: 27
      additionalJavaMailProperties:
        kind: parameter
        group: advanced
        label: advanced
        type: object
        javaType: java.util.Properties
        prefix: mail.
        multiValue: true
        deprecated: false
        secret: false
        description: Sets additional java mail properties that will append/override any default properties that is set based on all the other options. This is useful if you need to add some special options but want to keep the others as is.
        order: 28
      alternativeBodyHeader:
        kind: parameter
        group: advanced
        label: advanced
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        defaultValue: CamelMailAlternativeBody
        description: Specifies the key to an IN message header that contains an alternative email body. For example if you send emails in text/html format and want to provide an alternative mail body for non-HTML email clients set the alternative mail body with this key as a header.
        order: 29
      attachmentsContentTransferEncodingResolver:
        kind: parameter
        group: advanced
        label: advanced
        type: object
        javaType: org.apache.camel.component.mail.AttachmentsContentTransferEncodingResolver
        deprecated: false
        secret: false
        description: To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
        order: 30
      binding:
        kind: parameter
        group: advanced
        label: advanced
        type: object
        javaType: org.apache.camel.component.mail.MailBinding
        deprecated: false
        secret: false
        description: Sets the binding used to convert from a Camel message to and from a Mail message
        order: 31
      connectionTimeout:
        kind: parameter
        group: advanced
        label: advanced
        type: integer
        javaType: int
        deprecated: false
        secret: false
        defaultValue: "30000"
        description: The connection timeout in milliseconds.
        order: 32
      contentType:
        kind: parameter
        group: advanced
        label: advanced
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        defaultValue: text/plain
        description: The mail message content type. Use text/html for HTML mails.
        order: 33
      contentTypeResolver:
        kind: parameter
        group: advanced
        label: advanced
        type: object
        javaType: org.apache.camel.component.mail.ContentTypeResolver
        deprecated: false
        secret: false
        description: Resolver to determine Content-Type for file attachments.
        order: 34
      debugMode:
        kind: parameter
        group: advanced
        label: advanced
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Enable debug mode on the underlying mail framework. The SUN Mail framework logs the debug messages to System.out by default.
        order: 35
      headerFilterStrategy:
        kind: parameter
        group: advanced
        label: advanced
        type: object
        javaType: org.apache.camel.spi.HeaderFilterStrategy
        deprecated: false
        secret: false
        description: To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter headers.
        order: 36
      ignoreUnsupportedCharset:
        kind: parameter
        group: advanced
        label: advanced
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported then charset=XXX (where XXX represents the unsupported charset) is removed from the content-type and it relies on the platform default instead.
        order: 37
      ignoreUriScheme:
        kind: parameter
        group: advanced
        label: advanced
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported then charset=XXX (where XXX represents the unsupported charset) is removed from the content-type and it relies on the platform default instead.
        order: 38
      session:
        kind: parameter
        group: advanced
        label: advanced
        type: object
        javaType: javax.mail.Session
        deprecated: false
        secret: false
        description: Specifies the mail session that camel should use for all mail interactions. Useful in scenarios where mail sessions are created and managed by some other resource such as a JavaEE container. If this is not specified Camel automatically creates the mail session for you.
        order: 39
      synchronous:
        kind: parameter
        group: advanced
        label: advanced
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
        order: 40
      useInlineAttachments:
        kind: parameter
        group: advanced
        label: advanced
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: Whether to use disposition inline or attachment.
        order: 41
      idempotentRepository:
        kind: parameter
        group: filter
        label: consumer,filter
        type: object
        javaType: org.apache.camel.spi.IdempotentRepository<java.lang.String>
        deprecated: false
        secret: false
        description: A pluggable repository org.apache.camel.spi.IdempotentRepository which allows to cluster consuming from the same mailbox and let the repository coordinate whether a mail message is valid for the consumer to process. By default no repository is in use.
        order: 42
      idempotentRepositoryRemoveOnCommit:
        kind: parameter
        group: filter
        label: consumer,filter
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: true
        description: When using idempotent repository then when the mail message has been successfully processed and is committed should the message id be removed from the idempotent repository (default) or be kept in the repository. By default its assumed the message id is unique and has no value to be kept in the repository because the mail message will be marked as seen/moved or deleted to prevent it from being consumed again. And therefore having the message id stored in the idempotent repository has little value. However this option allows to store the message id for whatever reason you may have.
        order: 43
      searchTerm:
        kind: parameter
        group: filter
        label: consumer,filter
        type: object
        javaType: javax.mail.search.SearchTerm
        prefix: searchTerm.
        multiValue: true
        deprecated: false
        secret: false
        description: Refers to a javax.mail.search.SearchTerm which allows to filter mails based on search criteria such as subject body from sent after a certain date etc.
        order: 44
      backoffErrorThreshold:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: integer
        javaType: int
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        description: The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.
        order: 45
      backoffIdleThreshold:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: integer
        javaType: int
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        description: The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.
        order: 46
      backoffMultiplier:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: integer
        javaType: int
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        description: To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.
        order: 47
      delay:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: integer
        javaType: long
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: "60000"
        description: Milliseconds before the next poll.
        order: 48
      greedy:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: boolean
        javaType: boolean
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: false
        description: If greedy is enabled then the ScheduledPollConsumer will run immediately again if the previous run polled 1 or more messages.
        order: 49
      initialDelay:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: integer
        javaType: long
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: "1000"
        description: Milliseconds before the first poll starts. You can also specify time values using units such as 60s (60 seconds) 5m30s (5 minutes and 30 seconds) and 1h (1 hour).
        order: 50
      runLoggingLevel:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: string
        javaType: org.apache.camel.LoggingLevel
        enum:
        - TRACE
        - DEBUG
        - INFO
        - WARN
        - ERROR
        - OFF
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: TRACE
        description: The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.
        order: 51
      scheduledExecutorService:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: object
        javaType: java.util.concurrent.ScheduledExecutorService
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        description: Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.
        order: 52
      scheduler:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: string
        javaType: org.apache.camel.spi.ScheduledPollConsumerScheduler
        enum:
        - none
        - spring
        - quartz2
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: none
        description: To use a cron scheduler from either camel-spring or camel-quartz2 component
        order: 53
      schedulerProperties:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: object
        javaType: java.util.Map<java.lang.String,java.lang.Object>
        prefix: scheduler.
        multiValue: true
        deprecated: false
        secret: false
        description: To configure additional properties when using a custom scheduler or any of the Quartz2 Spring based scheduler.
        order: 54
      startScheduler:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: boolean
        javaType: boolean
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: true
        description: Whether the scheduler should be auto started.
        order: 55
      timeUnit:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: string
        javaType: java.util.concurrent.TimeUnit
        enum:
        - NANOSECONDS
        - MICROSECONDS
        - MILLISECONDS
        - SECONDS
        - MINUTES
        - HOURS
        - DAYS
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: MILLISECONDS
        description: Time unit for initialDelay and delay options.
        order: 56
      useFixedDelay:
        kind: parameter
        group: scheduler
        label: consumer,scheduler
        type: boolean
        javaType: boolean
        optionalPrefix: consumer.
        deprecated: false
        secret: false
        defaultValue: true
        description: Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.
        order: 57
      sortTerm:
        kind: parameter
        group: sort
        label: consumer,sort
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: false
        description: Sorting order for messages. Only natively supported for IMAP. Emulated to some degree when using POP3 or when IMAP server does not have the SORT capability.
        order: 58
      dummyTrustManager:
        kind: parameter
        group: security
        label: security
        type: boolean
        javaType: boolean
        deprecated: false
        secret: false
        defaultValue: false
        description: To use a dummy security setting for trusting all certificates. Should only be used for development mode and not production.
        order: 59
      password:
        kind: parameter
        group: security
        label: security
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: true
        description: The password for login
        order: 60
      sslContextParameters:
        kind: parameter
        group: security
        label: security
        type: object
        javaType: org.apache.camel.util.jsse.SSLContextParameters
        deprecated: false
        secret: false
        description: To configure security using SSLContextParameters.
        order: 61
      username:
        kind: parameter
        group: security
        label: security
        type: string
        javaType: java.lang.String
        deprecated: false
        secret: true
        description: The username for login
        order: 62
  documentation.adoc: |+
    [[Mail-MailComponent]]
    Mail Component
    ~~~~~~~~~~~~~~

    The mail component provides access to Email via Spring's Mail support
    and the underlying JavaMail system.

    Maven users will need to add the following dependency to their `pom.xml`
    for this component:

    [source,xml]
    ------------------------------------------------------------
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-mail</artifactId>
        <version>x.x.x</version>
        <!-- use the same version as your Camel core version -->
    </dependency>
    ------------------------------------------------------------

    WARNING: *Geronimo mail .jar*

    We have discovered that the geronimo mail `.jar` (v1.6) has a bug when
    polling mails with attachments. It cannot correctly identify the
    `Content-Type`. So, if you attach a `.jpeg` file to a mail and you poll
    it, the `Content-Type` is resolved as `text/plain` and not as
    `image/jpeg`. For that reason, we have added an
    `org.apache.camel.component.ContentTypeResolver` SPI interface which
    enables you to provide your own implementation and fix this bug by
    returning the correct Mime type based on the file name. So if the file
    name ends with `jpeg/jpg`, you can return `image/jpeg`.

    You can set your custom resolver on the `MailComponent` instance or on
    the `MailEndpoint` instance.


    TIP: *POP3 or IMAP*
    POP3 has some limitations and end users are encouraged to use IMAP if
    possible.

    INFO: *Using mock-mail for testing*
    You can use a mock framework for unit testing, which allows you to test
    without the need for a real mail server. However you should remember to
    not include the mock-mail when you go into production or other
    environments where you need to send mails to a real mail server. Just
    the presence of the mock-javamail.jar on the classpath means that it
    will kick in and avoid sending the mails.

    [[Mail-URIformat]]
    URI format
    ^^^^^^^^^^

    Mail endpoints can have one of the following URI formats (for the
    protocols, SMTP, POP3, or IMAP, respectively):

    [source,java]
    ---------------------------------------
    smtp://[username@]host[:port][?options]
    pop3://[username@]host[:port][?options]
    imap://[username@]host[:port][?options]
    ---------------------------------------

    The mail component also supports secure variants of these protocols
    (layered over SSL). You can enable the secure protocols by adding `s` to
    the scheme:

    [source,java]
    ----------------------------------------
    smtps://[username@]host[:port][?options]
    pop3s://[username@]host[:port][?options]
    imaps://[username@]host[:port][?options]
    ----------------------------------------

    You can append query options to the URI in the following format,
    `?option=value&option=value&...`


    [[Mail-Component-Options]]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^


    // component options: START
    The Mail component supports 2 options which are listed below.



    {% raw %}
    [width="100%",cols="2,1m,7",options="header"]
    |=======================================================================
    | Name | Java Type | Description
    | configuration | MailConfiguration | Sets the Mail configuration
    | contentTypeResolver | ContentTypeResolver | Resolver to determine Content-Type for file attachments.
    |=======================================================================
    {% endraw %}
    // component options: END



    [[Mail-Endpoint-Options]]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^


    // endpoint options: START
    The Mail component supports 63 endpoint options which are listed below:

    {% raw %}
    [width="100%",cols="2,1,1m,1m,5",options="header"]
    |=======================================================================
    | Name | Group | Default | Java Type | Description
    | host | common |  | String | *Required* The mail server host name
    | port | common |  | int | The port number of the mail server
    | bridgeErrorHandler | consumer | false | boolean | Allows for bridging the consumer to the Camel routing Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming messages or the likes will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions that will be logged at WARN/ERROR level and ignored.
    | closeFolder | consumer | true | boolean | Whether the consumer should close the folder after polling. Setting this option to false and having disconnect=false as well then the consumer keep the folder open between polls.
    | copyTo | consumer |  | String | After processing a mail message it can be copied to a mail folder with the given name. You can override this configuration value with a header with the key copyTo allowing you to copy messages to folder names configured at runtime.
    | delete | consumer | false | boolean | Deletes the messages after they have been processed. This is done by setting the DELETED flag on the mail message. If false the SEEN flag is set instead. As of Camel 2.10 you can override this configuration option by setting a header with the key delete to determine if the mail should be deleted or not.
    | disconnect | consumer | false | boolean | Whether the consumer should disconnect after polling. If enabled this forces Camel to connect on each poll.
    | handleFailedMessage | consumer | false | boolean | If the mail consumer cannot retrieve a given mail message then this option allows to handle the caused exception by the consumer's error handler. By enable the bridge error handler on the consumer then the Camel routing error handler can handle the exception instead. The default behavior would be the consumer throws an exception and no mails from the batch would be able to be routed by Camel.
    | maxMessagesPerPoll | consumer |  | int | Specifies the maximum number of messages to gather per poll. By default no maximum is set. Can be used to set a limit of e.g. 1000 to avoid downloading thousands of files when the server starts up. Set a value of 0 or negative to disable this option.
    | peek | consumer | true | boolean | Will mark the javax.mail.Message as peeked before processing the mail message. This applies to IMAPMessage messages types only. By using peek the mail will not be eager marked as SEEN on the mail server which allows us to rollback the mail message if there is an error processing in Camel.
    | sendEmptyMessageWhenIdle | consumer | false | boolean | If the polling consumer did not poll any files you can enable this option to send an empty message (no body) instead.
    | skipFailedMessage | consumer | false | boolean | If the mail consumer cannot retrieve a given mail message then this option allows to skip the message and move on to retrieve the next mail message. The default behavior would be the consumer throws an exception and no mails from the batch would be able to be routed by Camel.
    | unseen | consumer | true | boolean | Whether to limit by unseen mails only.
    | exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR level and ignored.
    | exchangePattern | consumer (advanced) |  | ExchangePattern | Sets the exchange pattern when the consumer creates an exchange.
    | fetchSize | consumer (advanced) | -1 | int | Sets the maximum number of messages to consume during a poll. This can be used to avoid overloading a mail server if a mailbox folder contains a lot of messages. Default value of -1 means no fetch size and all messages will be consumed. Setting the value to 0 is a special corner case where Camel will not consume any messages at all.
    | folderName | consumer (advanced) | INBOX | String | The folder to poll.
    | mailUidGenerator | consumer (advanced) |  | MailUidGenerator | A pluggable MailUidGenerator that allows to use custom logic to generate UUID of the mail message.
    | mapMailMessage | consumer (advanced) | true | boolean | Specifies whether Camel should map the received mail message to Camel body/headers. If set to true the body of the mail message is mapped to the body of the Camel IN message and the mail headers are mapped to IN headers. If this option is set to false then the IN message contains a raw javax.mail.Message. You can retrieve this raw message by calling exchange.getIn().getBody(javax.mail.Message.class).
    | pollStrategy | consumer (advanced) |  | PollingConsumerPollStrategy | A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel.
    | postProcessAction | consumer (advanced) |  | MailBoxPostProcessAction | Refers to an MailBoxPostProcessAction for doing post processing tasks on the mailbox once the normal processing ended.
    | bcc | producer |  | String | Sets the BCC email address. Separate multiple email addresses with comma.
    | cc | producer |  | String | Sets the CC email address. Separate multiple email addresses with comma.
    | from | producer | camel@localhost | String | The from email address
    | replyTo | producer |  | String | The Reply-To recipients (the receivers of the response mail). Separate multiple email addresses with a comma.
    | subject | producer |  | String | The Subject of the message being sent. Note: Setting the subject in the header takes precedence over this option.
    | to | producer |  | String | Sets the To email address. Separate multiple email addresses with comma.
    | javaMailSender | producer (advanced) |  | JavaMailSender | To use a custom org.apache.camel.component.mail.JavaMailSender for sending emails.
    | additionalJavaMailProperties | advanced |  | Properties | Sets additional java mail properties that will append/override any default properties that is set based on all the other options. This is useful if you need to add some special options but want to keep the others as is.
    | alternativeBodyHeader | advanced | CamelMailAlternativeBody | String | Specifies the key to an IN message header that contains an alternative email body. For example if you send emails in text/html format and want to provide an alternative mail body for non-HTML email clients set the alternative mail body with this key as a header.
    | attachmentsContentTransferEncodingResolver | advanced |  | AttachmentsContentTransferEncodingResolver | To use a custom AttachmentsContentTransferEncodingResolver to resolve what content-type-encoding to use for attachments.
    | binding | advanced |  | MailBinding | Sets the binding used to convert from a Camel message to and from a Mail message
    | connectionTimeout | advanced | 30000 | int | The connection timeout in milliseconds.
    | contentType | advanced | text/plain | String | The mail message content type. Use text/html for HTML mails.
    | contentTypeResolver | advanced |  | ContentTypeResolver | Resolver to determine Content-Type for file attachments.
    | debugMode | advanced | false | boolean | Enable debug mode on the underlying mail framework. The SUN Mail framework logs the debug messages to System.out by default.
    | headerFilterStrategy | advanced |  | HeaderFilterStrategy | To use a custom org.apache.camel.spi.HeaderFilterStrategy to filter headers.
    | ignoreUnsupportedCharset | advanced | false | boolean | Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported then charset=XXX (where XXX represents the unsupported charset) is removed from the content-type and it relies on the platform default instead.
    | ignoreUriScheme | advanced | false | boolean | Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported then charset=XXX (where XXX represents the unsupported charset) is removed from the content-type and it relies on the platform default instead.
    | session | advanced |  | Session | Specifies the mail session that camel should use for all mail interactions. Useful in scenarios where mail sessions are created and managed by some other resource such as a JavaEE container. If this is not specified Camel automatically creates the mail session for you.
    | synchronous | advanced | false | boolean | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported).
    | useInlineAttachments | advanced | false | boolean | Whether to use disposition inline or attachment.
    | idempotentRepository | filter |  | String> | A pluggable repository org.apache.camel.spi.IdempotentRepository which allows to cluster consuming from the same mailbox and let the repository coordinate whether a mail message is valid for the consumer to process. By default no repository is in use.
    | idempotentRepositoryRemoveOnCommit | filter | true | boolean | When using idempotent repository then when the mail message has been successfully processed and is committed should the message id be removed from the idempotent repository (default) or be kept in the repository. By default its assumed the message id is unique and has no value to be kept in the repository because the mail message will be marked as seen/moved or deleted to prevent it from being consumed again. And therefore having the message id stored in the idempotent repository has little value. However this option allows to store the message id for whatever reason you may have.
    | searchTerm | filter |  | SearchTerm | Refers to a javax.mail.search.SearchTerm which allows to filter mails based on search criteria such as subject body from sent after a certain date etc.
    | backoffErrorThreshold | scheduler |  | int | The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in.
    | backoffIdleThreshold | scheduler |  | int | The number of subsequent idle polls that should happen before the backoffMultipler should kick-in.
    | backoffMultiplier | scheduler |  | int | To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured.
    | delay | scheduler | 60000 | long | Milliseconds before the next poll.
    | greedy | scheduler | false | boolean | If greedy is enabled then the ScheduledPollConsumer will run immediately again if the previous run polled 1 or more messages.
    | initialDelay | scheduler | 1000 | long | Milliseconds before the first poll starts. You can also specify time values using units such as 60s (60 seconds) 5m30s (5 minutes and 30 seconds) and 1h (1 hour).
    | runLoggingLevel | scheduler | TRACE | LoggingLevel | The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that.
    | scheduledExecutorService | scheduler |  | ScheduledExecutorService | Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool.
    | scheduler | scheduler | none | ScheduledPollConsumerScheduler | To use a cron scheduler from either camel-spring or camel-quartz2 component
    | schedulerProperties | scheduler |  | Map | To configure additional properties when using a custom scheduler or any of the Quartz2 Spring based scheduler.
    | startScheduler | scheduler | true | boolean | Whether the scheduler should be auto started.
    | timeUnit | scheduler | MILLISECONDS | TimeUnit | Time unit for initialDelay and delay options.
    | useFixedDelay | scheduler | true | boolean | Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details.
    | sortTerm | sort |  | String | Sorting order for messages. Only natively supported for IMAP. Emulated to some degree when using POP3 or when IMAP server does not have the SORT capability.
    | dummyTrustManager | security | false | boolean | To use a dummy security setting for trusting all certificates. Should only be used for development mode and not production.
    | password | security |  | String | The password for login
    | sslContextParameters | security |  | SSLContextParameters | To configure security using SSLContextParameters.
    | username | security |  | String | The username for login
    |=======================================================================
    {% endraw %}
    // endpoint options: END




    [[Mail-Sampleendpoints]]
    Sample endpoints
    ++++++++++++++++

    Typically, you specify a URI with login credentials as follows (taking
    SMTP as an example):

    [source,java]
    ------------------------------------------------
    smtp://[username@]host[:port][?password=somepwd]
    ------------------------------------------------

    Alternatively, it is possible to specify both the user name and the
    password as query options:

    [source,java]
    -----------------------------------------------------
    smtp://host[:port]?password=somepwd&username=someuser
    -----------------------------------------------------

    For example:

    [source,java]
    ------------------------------------------------------------
    smtp://mycompany.mailserver:30?password=tiger&username=scott
    ------------------------------------------------------------

    [[Mail-Components]]
    Components
    ^^^^^^^^^^

    - link:imap.html[IMAP]
    - link:imaps.html[IMAPs]
    - link:pop3.html[POP3s]
    - link:pop3s.html[POP3s]
    - link:smtp.html[STMP]
    - link:smtps.html[SMTPs]

    [[Mail-DefaultPortsDefaultports]]
    Default ports
    +++++++++++++

    Default port numbers are supported. If the port number is omitted, Camel
    determines the port number to use based on the protocol.

    [width="100%",cols="10%,90%",options="header",]
    |=======================================================================
    |Protocol |Default Port Number
    |`SMTP` |`25`
    |`SMTPS` |`465`
    |`POP3` |`110`
    |`POP3S` |`995`
    |`IMAP` |`143`
    |`IMAPS` |`993`
    |=======================================================================

    [[Mail-SSLsupport]]
    SSL support
    ^^^^^^^^^^^

    The underlying mail framework is responsible for providing SSL support.
     You may either configure SSL/TLS support by completely specifying the
    necessary Java Mail API configuration options, or you may provide a
    configured SSLContextParameters through the component or endpoint
    configuration.

    [[Mail-UsingtheJSSEConfigurationUtility]]
    Using the JSSE Configuration Utility
    ++++++++++++++++++++++++++++++++++++

    As of *Camel 2.10*, the mail component supports SSL/TLS configuration
    through the link:camel-configuration-utilities.html[Camel JSSE
    Configuration Utility].  This utility greatly decreases the amount of
    component specific code you need to write and is configurable at the
    endpoint and component levels.  The following examples demonstrate how
    to use the utility with the mail component.

    [[Mail-Programmaticconfigurationoftheendpoint]]
    Programmatic configuration of the endpoint

    [source,java]
    ----------------------------------------------------------------------------------------------------------------------------------
    KeyStoreParameters ksp = new KeyStoreParameters();
    ksp.setResource("/users/home/server/truststore.jks");
    ksp.setPassword("keystorePassword");
    TrustManagersParameters tmp = new TrustManagersParameters();
    tmp.setKeyStore(ksp);
    SSLContextParameters scp = new SSLContextParameters();
    scp.setTrustManagers(tmp);
    Registry registry = ...
    registry.bind("sslContextParameters", scp);
    ...
    from(...)
    &nbsp; &nbsp; .to("smtps://smtp.google.com?username=user@gmail.com&password=password&sslContextParameters=#sslContextParameters");
    ----------------------------------------------------------------------------------------------------------------------------------

    [[Mail-SpringDSLbasedconfigurationofendpoint]]
    Spring DSL based configuration of endpoint

    [source,xml]
    ---------------------------------------------------------------------------------------------------------------------------
    ...
    <camel:sslContextParameters id="sslContextParameters">
      <camel:trustManagers>
        <camel:keyStore resource="/users/home/server/truststore.jks" password="keystorePassword"/>
      </camel:trustManagers>
    </camel:sslContextParameters>...
    ...
    <to uri="smtps://smtp.google.com?username=user@gmail.com&password=password&sslContextParameters=#sslContextParameters"/>...
    ---------------------------------------------------------------------------------------------------------------------------

    [[Mail-ConfiguringJavaMailDirectly]]
    Configuring JavaMail Directly
    +++++++++++++++++++++++++++++

    Camel uses SUN JavaMail, which only trusts certificates issued by well
    known Certificate Authorities (the default JVM trust configuration). If
    you issue your own certificates, you have to import the CA certificates
    into the JVM's Java trust/key store files, override the default JVM
    trust/key store files (see `SSLNOTES.txt` in JavaMail for details).

    [[Mail-MailMessageContent]]
    Mail Message Content
    ^^^^^^^^^^^^^^^^^^^^

    Camel uses the message exchange's IN body as the
    http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html[MimeMessage]
    text content. The body is converted to `String.class`.

    Camel copies all of the exchange's IN headers to the
    http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html[MimeMessage]
    headers.

    The subject of the
    http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html[MimeMessage]
    can be configured using a header property on the IN message. The code
    below demonstrates this:

    The same applies for other MimeMessage headers such as recipients, so
    you can use a header property as `To`:

    *Since Camel 2.11* When using the MailProducer the send the mail to
    server, you should be able to get the message id of the
    http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html[MimeMessage]
    with the key `CamelMailMessageId` from the Camel message header.

    [[Mail-Headerstakeprecedenceoverpre-configuredrecipients]]
    Headers take precedence over pre-configured recipients
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    The recipients specified in the message headers always take precedence
    over recipients pre-configured in the endpoint URI. The idea is that if
    you provide any recipients in the message headers, that is what you get.
    The recipients pre-configured in the endpoint URI are treated as a
    fallback.

    In the sample code below, the email message is sent to
    `davsclaus@apache.org`, because it takes precedence over the
    pre-configured recipient, `info@mycompany.com`. Any `CC` and `BCC`
    settings in the endpoint URI are also ignored and those recipients will
    not receive any mail. The choice between headers and pre-configured
    settings is all or nothing: the mail component _either_ takes the
    recipients exclusively from the headers or exclusively from the
    pre-configured settings. It is not possible to mix and match headers and
    pre-configured settings.

    [source,java]
    ------------------------------------------------------------------------------------------------------------
            Map<String, Object> headers = new HashMap<String, Object>();
            headers.put("to", "davsclaus@apache.org");

            template.sendBodyAndHeaders("smtp://admin@localhost?to=info@mycompany.com", "Hello World", headers);
    ------------------------------------------------------------------------------------------------------------

    [[Mail-Multiplerecipientsforeasierconfiguration]]
    Multiple recipients for easier configuration
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    It is possible to set multiple recipients using a comma-separated or a
    semicolon-separated list. This applies both to header settings and to
    settings in an endpoint URI. For example:

    [source,java]
    ------------------------------------------------------------------------------------------------
            Map<String, Object> headers = new HashMap<String, Object>();
            headers.put("to", "davsclaus@apache.org ; jstrachan@apache.org ; ningjiang@apache.org");
    ------------------------------------------------------------------------------------------------

    The preceding example uses a semicolon, `;`, as the separator character.

    [[Mail-Settingsendernameandemail]]
    Setting sender name and email
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    You can specify recipients in the format, `name <email>`, to include
    both the name and the email address of the recipient.

    For example, you define the following headers on the a
    link:message.html[Message]:

    [source,java]
    ---------------------------------------------------------
    Map headers = new HashMap();
    map.put("To", "Claus Ibsen <davsclaus@apache.org>");
    map.put("From", "James Strachan <jstrachan@apache.org>");
    map.put("Subject", "Camel is cool");
    ---------------------------------------------------------

    [[Mail-JavaMailAPI(exSUNJavaMail)]]
    JavaMail API (ex SUN JavaMail)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    https://java.net/projects/javamail/pages/Home[JavaMail API] is used
    under the hood for consuming and producing mails. +
     We encourage end-users to consult these references when using either
    POP3 or IMAP protocol. Note particularly that POP3 has a much more
    limited set of features than IMAP.

    * https://javamail.java.net/nonav/docs/api/com/sun/mail/pop3/package-summary.html[JavaMail
    POP3 API]
    * https://javamail.java.net/nonav/docs/api/com/sun/mail/imap/package-summary.html[JavaMail
    IMAP API]
    * And generally about the
    https://javamail.java.net/nonav/docs/api/javax/mail/Flags.html[MAIL
    Flags]

    [[Mail-Samples]]
    Samples
    ^^^^^^^

    We start with a simple route that sends the messages received from a JMS
    queue as emails. The email account is the `admin` account on
    `mymailserver.com`.

    [source,java]
    -------------------------------------------------------------------------------------
    from("jms://queue:subscription").to("smtp://admin@mymailserver.com?password=secret");
    -------------------------------------------------------------------------------------

    In the next sample, we poll a mailbox for new emails once every minute.
    Notice that we use the special `consumer` option for setting the poll
    interval, `consumer.delay`, as 60000 milliseconds = 60 seconds.

    [source,java]
    -------------------------------------------------------
    from("imap://admin@mymailserver.com
         password=secret&unseen=true&consumer.delay=60000")
        .to("seda://mails");
    -------------------------------------------------------

    In this sample we want to send a mail to multiple recipients:

    [[Mail-Sendingmailwithattachmentsample]]
    Sending mail with attachment sample
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


    WARNING: *Attachments are not support by all Camel components*
    The _Attachments API_ is based on the Java Activation Framework and is
    generally only used by the Mail API. Since many of the other Camel
    components do not support attachments, the attachments could potentially
    be lost as they propagate along the route. The rule of thumb, therefore,
    is to add attachments just before sending a message to the mail
    endpoint.


    The mail component supports attachments. In the sample below, we send a
    mail message containing a plain text message with a logo file
    attachment.

    [[Mail-SSLsample]]
    SSL sample
    ^^^^^^^^^^

    In this sample, we want to poll our Google mail inbox for mails. To
    download mail onto a local mail client, Google mail requires you to
    enable and configure SSL. This is done by logging into your Google mail
    account and changing your settings to allow IMAP access. Google have
    extensive documentation on how to do this.

    [source,java]
    -------------------------------------------------------------------------------------
    from("imaps://imap.gmail.com?username=YOUR_USERNAME@gmail.com&password=YOUR_PASSWORD"
        + "&delete=false&unseen=true&consumer.delay=60000").to("log:newmail");
    -------------------------------------------------------------------------------------

    The preceding route polls the Google mail inbox for new mails once every
    minute and logs the received messages to the `newmail` logger
    category. +
     Running the sample with `DEBUG` logging enabled, we can monitor the
    progress in the logs:

    [source,java]
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------
    2008-05-08 06:32:09,640 DEBUG MailConsumer - Connecting to MailStore imaps//imap.gmail.com:993 (SSL enabled), folder=INBOX
    2008-05-08 06:32:11,203 DEBUG MailConsumer - Polling mailfolder: imaps//imap.gmail.com:993 (SSL enabled), folder=INBOX
    2008-05-08 06:32:11,640 DEBUG MailConsumer - Fetching 1 messages. Total 1 messages.
    2008-05-08 06:32:12,171 DEBUG MailConsumer - Processing message: messageNumber=[332], from=[James Bond <007@mi5.co.uk>], to=YOUR_USERNAME@gmail.com], subject=[...
    2008-05-08 06:32:12,187 INFO  newmail - Exchange[MailMessage: messageNumber=[332], from=[James Bond <007@mi5.co.uk>], to=YOUR_USERNAME@gmail.com], subject=[...
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------

    [[Mail-Consumingmailswithattachmentsample]]
    Consuming mails with attachment sample
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    In this sample we poll a mailbox and store all attachments from the
    mails as files. First, we define a route to poll the mailbox. As this
    sample is based on google mail, it uses the same route as shown in the
    SSL sample:

    [source,java]
    ---------------------------------------------------------------------------------------
    from("imaps://imap.gmail.com?username=YOUR_USERNAME@gmail.com&password=YOUR_PASSWORD"
        + "&delete=false&unseen=true&consumer.delay=60000").process(new MyMailProcessor());
    ---------------------------------------------------------------------------------------

    Instead of logging the mail we use a processor where we can process the
    mail from java code:

    [source,java]
    ---------------------------------------------------------------------------------
        public void process(Exchange exchange) throws Exception {
            // the API is a bit clunky so we need to loop
            Map<String, DataHandler> attachments = exchange.getIn().getAttachments();
            if (attachments.size() > 0) {
                for (String name : attachments.keySet()) {
                    DataHandler dh = attachments.get(name);
                    // get the file name
                    String filename = dh.getName();

                    // get the content and convert it to byte[]
                    byte[] data = exchange.getContext().getTypeConverter()
                                      .convertTo(byte[].class, dh.getInputStream());

                    // write the data to a file
                    FileOutputStream out = new FileOutputStream(filename);
                    out.write(data);
                    out.flush();
                    out.close();
                }
            }
       }
    ---------------------------------------------------------------------------------

    As you can see the API to handle attachments is a bit clunky but it's
    there so you can get the `javax.activation.DataHandler` so you can
    handle the attachments using standard API.

    [[Mail-Howtosplitamailmessagewithattachments]]
    How to split a mail message with attachments
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    In this example we consume mail messages which may have a number of
    attachments. What we want to do is to use the
    link:splitter.html[Splitter] EIP per individual attachment, to process
    the attachments separately. For example if the mail message has 5
    attachments, we want the link:splitter.html[Splitter] to process five
    messages, each having a single attachment. To do this we need to provide
    a custom link:expression.html[Expression] to the
    link:splitter.html[Splitter] where we provide a List<Message> that
    contains the five messages with the single attachment.

    The code is provided out of the box in Camel 2.10 onwards in the
    `camel-mail` component. The code is in the class:
    `org.apache.camel.component.mail.SplitAttachmentsExpression`, which you
    can find the source code
    https://svn.apache.org/repos/asf/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/SplitAttachmentsExpression.java[here]

    In the Camel route you then need to use this
    link:expression.html[Expression] in the route as shown below:

    If you use XML DSL then you need to declare a method call expression in
    the link:splitter.html[Splitter] as shown below

    [source,xml]
    ---------------------------------------------------------------------------------
    <split>
      <method beanType="org.apache.camel.component.mail.SplitAttachmentsExpression"/>
      <to uri="mock:split"/>
    </split>
    ---------------------------------------------------------------------------------

     

    From Camel 2.16 onwards you can also split the attachments as byte[] to
    be stored as the message body. This is done by creating the expression
    with boolean true

    [source,java]
    --------------------------------------------------------------------
    SplitAttachmentsExpression split = SplitAttachmentsExpression(true);
    --------------------------------------------------------------------

    And then use the expression with the splitter eip.

    [[Mail-UsingcustomSearchTerm]]
    Using custom SearchTerm
    ^^^^^^^^^^^^^^^^^^^^^^^

    *Available as of Camel 2.11*

    You can configure a `searchTerm` on the `MailEndpoint` which allows you
    to filter out unwanted mails.

    For example to filter mails to contain Camel in either Subject or Text
    you can do as follows:

    [source,xml]
    -------------------------------------------------------------------------------------------------
    <route>
      <from uri="imaps://mymailseerver?username=foo&password=secret&searchTerm.subjectOrBody=Camel"/>
      <to uri="bean:myBean"/>
    </route>
    -------------------------------------------------------------------------------------------------

    Notice we use the `"searchTerm.subjectOrBody"` as parameter key to
    indicate that we want to search on mail subject or body, to contain the
    word "Camel". +
     The class `org.apache.camel.component.mail.SimpleSearchTerm` has a
    number of options you can configure:

    Or to get the new unseen emails going 24 hours back in time you can do.
    Notice the "now-24h" syntax. See the table below for more details.

    [source,xml]
    --------------------------------------------------------------------------------------------------
    <route>
      <from uri="imaps://mymailseerver?username=foo&password=secret&searchTerm.fromSentDate=now-24h"/>
      <to uri="bean:myBean"/>
    </route>
    --------------------------------------------------------------------------------------------------

    You can have multiple searchTerm in the endpoint uri configuration. They
    would then be combined together using AND operator, eg so both
    conditions must match. For example to get the last unseen emails going
    back 24 hours which has Camel in the mail subject you can do:

    [source,xml]
    ---------------------------------------------------------------------------------------------------------------------------
    <route>
      <from uri="imaps://mymailseerver?username=foo&password=secret&searchTerm.subject=Camel&searchTerm.fromSentDate=now-24h"/>
      <to uri="bean:myBean"/>
    </route>
    ---------------------------------------------------------------------------------------------------------------------------

    The `SimpleSearchTerm` is designed to be easily configurable from a
    POJO, so you can also configure it using a <bean> style in XML

    [source,java]
    ---------------------------------------------------------------------------------
    <bean id="mySearchTerm" class="org.apache.camel.component.mail.SimpleSearchTerm">
      <property name="subject" value="Order"/>
      <property name="to" value="acme-order@acme.com"/>
      <property name="fromSentDate" value="now"/>
     </bean>
    ---------------------------------------------------------------------------------

    You can then refer to this bean, using #beanId in your Camel route as
    shown:

    [source,xml]
    -------------------------------------------------------------------------------------------
    <route>
      <from uri="imaps://mymailseerver?username=foo&password=secret&searchTerm=#mySearchTerm"/>
      <to uri="bean:myBean"/>
    </route>
    -------------------------------------------------------------------------------------------

    In Java there is a builder class to build compound
    `SearchTerms` using the `org.apache.camel.component.mail.SearchTermBuilder`
    class. This allows you to build complex terms such as:

    [source,java]
    --------------------------------------------------------------
    // we just want the unseen mails which is not spam
    SearchTermBuilder builder = new SearchTermBuilder();

    builder.unseen().body(Op.not, "Spam").subject(Op.not, "Spam")
      // which was sent from either foo or bar
      .from("foo@somewhere.com").from(Op.or, "bar@somewhere.com");
      // .. and we could continue building the terms

    SearchTerm term = builder.build();
    --------------------------------------------------------------

    [[Mail-SeeAlso]]
    See Also
    ^^^^^^^^

    * link:configuring-camel.html[Configuring Camel]
    * link:component.html[Component]
    * link:endpoint.html[Endpoint]
    * link:getting-started.html[Getting Started]

