Name

Mail — provides access to e-mail systems

Overview

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

[Warning]Warning

The Geronimo mail JAR (v1.6) has a bug when polling e-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, 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.

[Note]Note

Because POP3 has some limitations, end users are encouraged to use IMAP when possible.

[Important]Important

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 not to include mock-mail when you go into production or in other environments where you need to send mails to a real mail server. Just the presence of the mock-javamail.jar on the classpath will trigger the mock-mail functionality.

URI format

Mail endpoints can have one of the URI formats listed in Table 34, “Mail URI Formats”.

Table 34. Mail URI Formats

Mail ProtocolURI Format
SMTP smtp(s)://[username@]host[:port][?options]
POP3 pop3(s)://[username@]host[:port][?options]
IMAP imap(s)://[username@]host[:port][?options]

Mail endpoints also supports secure variants of these protocols that are layered over SSL. You can enable the secure protocols by adding s to the scheme.

Default ports

Table 35, “Default mail port numbers” lists the default port numbers that are used if the port number is omitted.

Table 35. Default mail port numbers

ProtocolDefault Port Number
SMTP25
SMTPS465
POP3110
POP3S995
IMAP143
IMAPS993

Options

Table 36, “Mail endpoint options” describes the options for Mail endpoints.

Table 36. Mail endpoint options

PropertyDefaultDescription
host   The host name or IP address to connect to.
port See Table 35, “Default mail port numbers” The TCP port number to connect on.
username   The user name on the email server.
password  The password on the email server.
ignoreUriScheme false If false, Apache Camel uses the scheme to determine the transport protocol (POP, IMAP, SMTP etc.)
defaultEncoding   The default encoding to use for Mime Messages.
contentType text/plain The mail message content type. Use text/html for HTML mails.
folderName INBOX The folder to poll.
to username@host The recipients. Separate multiple email addresses with a comma.
replyTo alias@host The Reply-To recipients (receivers of the response mail). Separate multiple email addresses with a comma.
CC  The CC recipients. Separate multiple email addresses with a comma.
BCC  The BCC recipients. Separate multiple email addresses with a comma.
from camel@localhost The FROM email address.
subject  The Subject of the message being sent. Note: Setting the subject in the header takes precedence over this option.
delete false 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.
unseen true Is used to only fetch unseen(new) messages. POP3 does not support the SEEN flag.
fetchSize -1 Specifies the maximum number of messages to consume during a poll.The default value of -1 means all available messages will be consumed. Setting the value to 0 means Apache Camel will not consume any messages.
alternativeBodyHeader CamelMailAlternativeBody 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.
debugMode false Specifies if debug mode is enabled on the underlying mail framework. The SUN Mail framework logs the debug messages to System.out by default.
connectionTimeout 30000 The connection timeout can be configured in milliseconds.
consumer.initialDelay 1000 Milliseconds before the polling starts.
consumer.delay 60000 Specifies the consumer delay in milliseconds.
consumer.useFixedDelay false Set to true to use a fixed delay between polls, otherwise fixed rate is used. See ScheduledExecutorService in JDK for details.
mail.XXX  You can set any additional java mail properties.
maxMessagesPerPoll 0 Specifies the maximum number of messages to gather per poll. The default value of 0 (or a negative value) disables this option.
javaMailSender  Specifies a custom implementation of the Spring JavaMailSender interface in order to use a custom email implementation. If none provided, Apache Camel uses the default Spring JavaMailSenderImpl implementation.
ignoreUnsupportedCharset false Option to let Apache Camel ignore unsupported charsets in the local JVM when sending mails. If the charset is unsupported then charset=XXX is removed from the content-type and it relies on the platform default instead.

SSL support

The underlying mail framework is responsible for providing SSL support. Apache Camel uses SUN JavaMail, which only trusts certificates issued by well known Certificate Authorities. So if you issue your own certificate, you have to import it into the local Java keystore file (see SSLNOTES.txt in JavaMail for details).

SUN JavaMail

SUN JavaMail 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.