camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Mail
Date Tue, 13 Nov 2012 17:20:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Mail">Mail</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{ignoreUnsupportedCharset}} | {{false}} | 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. | <br>| {{sslContextParameters}} | {{null}} | *Camel 2.10:* Reference to a {{org.apache.camel.util.jsse.SSLContextParameters}} in the [Registry|http://camel.apache.org/registry.html].&amp;nbsp; This reference overrides any configured SSLContextParameters at the component level.&amp;nbsp; See [Using the JSSE Configuration Utility|http://camel.apache.org/http4.html#HTTP4-UsingtheJSSEConfigurationUtility]. | <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">| {{searchTerm}} | {{null}} | *Camel 2.11:* 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. See further below for examples. | <br>| {{searchTerm.xxx}} | {{null}} | *Camel 2.11:* To configure search terms directly from the endpoint uri, which supports a limited number of terms defined by the {{org.apache.camel.component.mail.SimpleSearchTerm}} class. See further below for examples. |  <br></td></tr>
            <tr><td class="diff-unchanged" >{div} <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h3. Using custom SearchTerm <br>*Available as of Camel 2.11* <br> <br>You can configure a {{searchTerm}} on the {{MailEndpoint}} which allows you to filter out unwanted mails.  <br> <br>For example to filter mails to contain Camel in either Subject or Text you can do as follows: <br>{code:xml} <br>&lt;route&gt; <br>  &lt;from uri=&quot;imaps://mymailseerver?username=foo&amp;password=secret&amp;searchTerm.subjectOrBody=Camel&quot;/&gt; <br>  &lt;to uri=&quot;bean:myBean&quot;/&gt; <br>&lt;/route&gt; <br>{code} <br> <br>Notice we use the {{&quot;searchTerm.subjectOrBody&quot;}} as parameter key to indicate that we want to search on mail subject or body, to contain the word &quot;Camel&quot;. <br>The class {{org.apache.camel.component.mail.SimpleSearchTerm}} has a number of options you can configure: <br> <br>{div:class=confluenceTableSmall} <br>|| Option || Default || Description || <br>| unseen | {{true}} | Whether to limit by unseen mails only. | <br>| subjectOrBody | {{null}} | To limit by subject or body to contain the word. | <br>| subject | {{null}} | The subject must contain the word. | <br>| body | {{null}} | The body must contain the word. | <br>| from | {{null}} | The mail must be from a given email pattern. | <br>| to | {{null}} | The mail must be to a given email pattern. | <br>| fromSentDate | {{null}} | The mail must be sent after or equals (GE) a given date. The date pattern is {{yyyy-MM-dd HH:mm:SS}}, eg use {{&quot;2012-01-01 00:00:00&quot;}} to be from the year 2012 onwards. You can use {{&quot;now&quot;}} for current timestamp. | <br>| toSentDate | {{null}} | The mail must be sent before or equals (BE) a given date. The date pattern is {{yyyy-MM-dd HH:mm:SS}}, eg use {{&quot;2012-01-01 00:00:00&quot;}} to be before the year 2012. You can use {{&quot;now&quot;}} for current timestamp. | <br>{div} <br> <br>The {{SimpleSearchTerm}} is designed to be easily configurable from a POJO, so you can also configure it using a &lt;bean&gt; style in XML <br>{code} <br>&lt;bean id=&quot;mySearchTerm&quot; class=&quot;org.apache.camel.component.mail.SimpleSearchTerm&quot;&gt; <br>  &lt;property name=&quot;subject&quot; value=&quot;Order&quot;/&gt; <br>  &lt;property name=&quot;to&quot; value=&quot;acme-order@acme.com&quot;/&gt; <br>  &lt;property name=&quot;fromSentDate&quot; value=&quot;now&quot;/&gt; <br> &lt;/bean&gt; <br>{code} <br> <br>You can then refer to this bean, using #beanId in your Camel route as shown: <br>{code:xml} <br>&lt;route&gt; <br>  &lt;from uri=&quot;imaps://mymailseerver?username=foo&amp;password=secret&amp;searchTerm=#mySearchTerm&quot;/&gt; <br>  &lt;to uri=&quot;bean:myBean&quot;/&gt; <br>&lt;/route&gt; <br>{code} <br> <br>In Java there is a builder class to build compound {{SearchTerm}}s using the {{org.apache.camel.component.mail.SearchTermBuilder}} class. <br>This allows you to build complex terms such as: <br>{code} <br>// we just want the unseen mails which is not spam <br>SearchTermBuilder builder = new SearchTermBuilder(); <br> <br>builder.unseen().body(Op.not, &quot;Spam&quot;).subject(Op.not, &quot;Spam&quot;) <br>  // which was sent from either foo or bar <br>  .from(&quot;foo@somewhere.com&quot;).from(Op.or, &quot;bar@somewhere.com&quot;); <br>  // .. and we could continue building the terms <br> <br>SearchTerm term = builder.build(); <br>{code} <br> <br></td></tr>
            <tr><td class="diff-unchanged" >{include:Endpoint See Also} <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Mail-MailComponent"></a>Mail Component</h2>

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

<p>Maven users will need to add the following dependency to their <tt>pom.xml</tt> for this component:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;dependency&gt;</span>
    <span class="code-tag">&lt;groupId&gt;</span>org.apache.camel<span class="code-tag">&lt;/groupId&gt;</span>
    <span class="code-tag">&lt;artifactId&gt;</span>camel-mail<span class="code-tag">&lt;/artifactId&gt;</span>
    <span class="code-tag">&lt;version&gt;</span>x.x.x<span class="code-tag">&lt;/version&gt;</span>
    <span class="code-tag"><span class="code-comment">&lt;!-- use the same version as your Camel core version --&gt;</span></span>
<span class="code-tag">&lt;/dependency&gt;</span>
</pre>
</div></div>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Geronimo mail .jar</b><br />We have discovered that the geronimo mail <tt>.jar</tt> (v1.6) has a bug when polling mails with attachments. It cannot correctly identify the <tt>Content-Type</tt>. So, if you attach a <tt>.jpeg</tt> file to a mail and you poll it, the <tt>Content-Type</tt> is resolved as <tt>text/plain</tt> and not as <tt>image/jpeg</tt>. For that reason, we have added an <tt>org.apache.camel.component.ContentTypeResolver</tt> 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 <tt>jpeg/jpg</tt>, you can return <tt>image/jpeg</tt>.

<p>You can set your custom resolver on the <tt>MailComponent</tt> instance or on the <tt>MailEndpoint</tt> instance.</p></td></tr></table></div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>POP3 or IMAP</b><br />POP3 has some limitations and end users are encouraged to use IMAP if possible.</td></tr></table></div>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Using mock-mail for testing</b><br />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.</td></tr></table></div>

<h3><a name="Mail-URIformat"></a>URI format</h3>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//[username@]host[:port][?options]
</span>pop3:<span class="code-comment">//[username@]host[:port][?options]
</span>imap:<span class="code-comment">//[username@]host[:port][?options]</span>
</pre>
</div></div>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtps:<span class="code-comment">//[username@]host[:port][?options]
</span>pop3s:<span class="code-comment">//[username@]host[:port][?options]
</span>imaps:<span class="code-comment">//[username@]host[:port][?options]</span>
</pre>
</div></div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h4><a name="Mail-Sampleendpoints"></a>Sample endpoints</h4>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//[username@]host[:port][?password=somepwd]</span>
</pre>
</div></div>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//host[:port]?password=somepwd&amp;username=someuser</span>
</pre>
</div></div>

<p>For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
smtp:<span class="code-comment">//mycompany.mailserver:30?password=tiger&amp;username=scott</span>
</pre>
</div></div>

<h4><a name="Mail-Defaultports"></a><a name="Mail-DefaultPorts"></a>Default ports</h4>

<p>Default port numbers are supported. If the port number is omitted, Camel determines the port number to use based on the protocol.</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Protocol </th>
<th class='confluenceTh'> Default Port Number </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>SMTP</tt> </td>
<td class='confluenceTd'> <tt>25</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>SMTPS</tt> </td>
<td class='confluenceTd'> <tt>465</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>POP3</tt> </td>
<td class='confluenceTd'> <tt>110</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>POP3S</tt> </td>
<td class='confluenceTd'> <tt>995</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>IMAP</tt> </td>
<td class='confluenceTd'> <tt>143</tt> </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>IMAPS</tt> </td>
<td class='confluenceTd'> <tt>993</tt> </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Mail-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Property </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>host</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The host name or IP address to connect to. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>port</tt> </td>
<td class='confluenceTd'> See <a href="#Mail-DefaultPorts">DefaultPorts</a> </td>
<td class='confluenceTd'> The TCP port number to connect on. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>username</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> The user name on the email server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>password</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The password on the email server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreUriScheme</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>false</tt>, Camel uses the scheme to determine the transport protocol (POP, IMAP, SMTP etc.) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>defaultEncoding</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The default encoding to use for Mime Messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>contentType</tt> </td>
<td class='confluenceTd'> <tt>text/plain</tt> </td>
<td class='confluenceTd'> The mail message content type. Use <tt>text/html</tt> for HTML mails. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>folderName</tt> </td>
<td class='confluenceTd'> <tt>INBOX</tt> </td>
<td class='confluenceTd'> The folder to poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>destination</tt> </td>
<td class='confluenceTd'> <tt>username@host</tt> </td>
<td class='confluenceTd'> <b>@deprecated</b> Use the <tt>to</tt> option instead. The <tt>TO</tt> recipients (receivers of the email). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>to</tt> </td>
<td class='confluenceTd'> <tt>username@host</tt> </td>
<td class='confluenceTd'> The TO recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>replyTo</tt> </td>
<td class='confluenceTd'> <tt>alias@host</tt> </td>
<td class='confluenceTd'> As of <b>Camel 2.8.4, 2.9.1&#43;</b>, the Reply-To recipients (the receivers of the response mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>CC</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'>The CC recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>BCC</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The BCC recipients (the receivers of the mail). Separate multiple email addresses with a comma. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>from</tt> </td>
<td class='confluenceTd'> <tt>camel@localhost</tt> </td>
<td class='confluenceTd'> The FROM email address. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>subject</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> As of <b>Camel 2.3</b>, the Subject of the message being sent. Note: Setting the subject in the header takes precedence over this option. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>delete</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Deletes the messages after they have been processed. This is done by setting the <tt>DELETED</tt> flag on the mail message. If <tt>false</tt>, the <tt>SEEN</tt> flag is set instead. As of <b>Camel 2.10</b> you can override this configuration option by setting a header with the key <tt>delete</tt> to determine if the mail should be deleted or not. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>unseen</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> It is possible to configure a consumer endpoint so that it processes only unseen messages (that is, new messages) or all messages. Note that Camel always skips deleted messages. The default option of <tt>true</tt> will filter to only unseen messages.  POP3 does not support the <tt>SEEN</tt> flag, so this option is not supported in POP3; use IMAP instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>copyTo</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Consumer only. 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 <tt>copyTo</tt>, allowing you to copy messages to folder names configured at runtime. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>fetchSize</tt> </td>
<td class='confluenceTd'> <tt>&#45;1</tt> </td>
<td class='confluenceTd'> 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 <tt>&#45;1</tt> 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>alternativeBodyHeader</tt> </td>
<td class='confluenceTd'> <tt>CamelMailAlternativeBody</tt> </td>
<td class='confluenceTd'> Specifies the key to an IN message header that contains an alternative email body. For example, if you send emails in <tt>text/html</tt> 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>debugMode</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Enable debug mode on the underlying mail framework. The SUN Mail framework logs the debug messages to <tt>System.out</tt> by default. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>connectionTimeout</tt> </td>
<td class='confluenceTd'> <tt>30000</tt> </td>
<td class='confluenceTd'> The connection timeout in milliseconds. Default is 30 seconds. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.initialDelay</tt> </td>
<td class='confluenceTd'> <tt>1000</tt> </td>
<td class='confluenceTd'> Milliseconds before the polling starts. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.delay</tt> </td>
<td class='confluenceTd'> <tt>60000</tt> </td>
<td class='confluenceTd'> Camel will poll the mailbox only once a minute by default to avoid overloading the mail server. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>consumer.useFixedDelay</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Set to <tt>true</tt> to use a fixed delay between polls, otherwise fixed rate is used. See <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ScheduledExecutorService.html" class="external-link" rel="nofollow">ScheduledExecutorService</a> in JDK for details. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>disconnect</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8.3/2.9:</b> Whether the consumer should disconnect after polling. If enabled this forces Camel to connect on each poll. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mail.XXX</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Set any <a href="http://java.sun.com/products/javamail/javadocs/index.html" class="external-link" rel="nofollow">additional java mail properties</a>. For instance if you want to set a special property when using POP3 you can now provide the option directly in the URI such as: <tt>mail.pop3.forgettopheaders=true</tt>. You can set multiple such options, for example: <tt>mail.pop3.forgettopheaders=true&amp;mail.mime.encodefilename=true</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>mapMailMessage</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> 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 <tt>javax.mail.Message</tt>. You can retrieve this raw message by calling <tt>exchange.getIn().getBody(javax.mail.Message.class)</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxMessagesPerPoll</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> 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. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>javaMailSender</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> Specifies a pluggable <tt>org.springframework.mail.javamail.JavaMailSender</tt> instance in order to use a custom email implementation. If none provided, Camel uses the default <tt>org.springframework.mail.javamail.JavaMailSenderImpl</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>ignoreUnsupportedCharset</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Option to let Camel ignore unsupported charset in the local JVM when sending mails. If the charset is unsupported then <tt>charset=XXX</tt> (where <tt>XXX</tt> represents the unsupported charset) is removed from the <tt>content-type</tt> and it relies on the platform default instead. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>sslContextParameters</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.10:</b> Reference to a <tt>org.apache.camel.util.jsse.SSLContextParameters</tt> in the <a href="http://camel.apache.org/registry.html" class="external-link" rel="nofollow">Registry</a>.&nbsp; This reference overrides any configured SSLContextParameters at the component level.&nbsp; See <a href="http://camel.apache.org/http4.html#HTTP4-UsingtheJSSEConfigurationUtility" class="external-link" rel="nofollow">Using the JSSE Configuration Utility</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>searchTerm</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> Refers to a <tt>javax.mail.search.SearchTerm</tt> which allows to filter mails based on search criteria such as subject, body, from, sent after a certain date etc. See further below for examples. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>searchTerm.xxx</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <b>Camel 2.11:</b> To configure search terms directly from the endpoint uri, which supports a limited number of terms defined by the <tt>org.apache.camel.component.mail.SimpleSearchTerm</tt> class. See further below for examples. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="Mail-SSLsupport"></a>SSL support</h3>

<p>The underlying mail framework is responsible for providing SSL support. &nbsp;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.</p>

<h4><a name="Mail-UsingtheJSSEConfigurationUtility"></a>Using the JSSE Configuration Utility</h4>

<p>As of <b>Camel 2.10</b>, the mail component supports SSL/TLS configuration through the <a href="/confluence/display/CAMEL/Camel+Configuration+Utilities" title="Camel Configuration Utilities">Camel JSSE Configuration Utility</a>.&nbsp; This utility greatly decreases the amount of component specific code you need to write and is configurable at the endpoint and component levels.&nbsp; The following examples demonstrate how to use the utility with the mail component.</p>

<h5><a name="Mail-Programmaticconfigurationoftheendpoint"></a>Programmatic configuration of the endpoint</h5>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
KeyStoreParameters ksp = <span class="code-keyword">new</span> KeyStoreParameters();
ksp.setResource(<span class="code-quote">"/users/home/server/truststore.jks"</span>);
ksp.setPassword(<span class="code-quote">"keystorePassword"</span>);
TrustManagersParameters tmp = <span class="code-keyword">new</span> TrustManagersParameters();
tmp.setKeyStore(ksp);
SSLContextParameters scp = <span class="code-keyword">new</span> SSLContextParameters();
scp.setTrustManagers(tmp);
Registry registry = ...
registry.bind(<span class="code-quote">"sslContextParameters"</span>, scp);
...
from(...)
&amp;nbsp; &amp;nbsp; .to(<span class="code-quote">"smtps:<span class="code-comment">//smtp.google.com?username=user@gmail.com&amp;password=password&amp;sslContextParameters=#sslContextParameters"</span>);</span>
</pre>
</div></div>

<h5><a name="Mail-SpringDSLbasedconfigurationofendpoint"></a>Spring DSL based configuration of endpoint</h5>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
...
<span class="code-tag">&lt;camel:sslContextParameters id=<span class="code-quote">"sslContextParameters"</span>&gt;</span>
  <span class="code-tag">&lt;camel:trustManagers&gt;</span>
    <span class="code-tag">&lt;camel:keyStore resource=<span class="code-quote">"/users/home/server/truststore.jks"</span> password=<span class="code-quote">"keystorePassword"</span>/&gt;</span>
  <span class="code-tag">&lt;/camel:trustManagers&gt;</span>
<span class="code-tag">&lt;/camel:sslContextParameters&gt;</span>...
...
<span class="code-tag">&lt;to uri=<span class="code-quote">"smtps://smtp.google.com?username=user@gmail.com&amp;password=password&amp;sslContextParameters=#sslContextParameters"</span>/&gt;</span>...
</pre>
</div></div>

<h4><a name="Mail-ConfiguringJavaMailDirectly"></a>Configuring JavaMail Directly</h4>

<p>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 <tt>SSLNOTES.txt</tt> in JavaMail for details).</p>

<h3><a name="Mail-MailMessageContent"></a>Mail Message Content</h3>

<p>Camel uses the message exchange's IN body as the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" class="external-link" rel="nofollow">MimeMessage</a> text content. The body is converted to <tt>String.class</tt>.</p>

<p>Camel copies all of the exchange's IN headers to the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" class="external-link" rel="nofollow">MimeMessage</a> headers.</p>

<p>The subject of the <a href="http://java.sun.com/javaee/5/docs/api/javax/mail/internet/MimeMessage.html" class="external-link" rel="nofollow">MimeMessage</a> can be configured using a header property on the IN message. The code below demonstrates this:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"direct:a"</span>).setHeader(<span class="code-quote">"subject"</span>, constant(subject)).to(<span class="code-quote">"smtp:<span class="code-comment">//james2@localhost"</span>);</span>
</pre>
</div></div>

<p>The same applies for other MimeMessage headers such as recipients, so you can use a header property as <tt>To</tt>:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; map = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
map.put(<span class="code-quote">"To"</span>, <span class="code-quote">"davsclaus@apache.org"</span>);
map.put(<span class="code-quote">"From"</span>, <span class="code-quote">"jstrachan@apache.org"</span>);
map.put(<span class="code-quote">"Subject"</span>, <span class="code-quote">"Camel rocks"</span>);

<span class="code-object">String</span> body = <span class="code-quote">"Hello Claus.\nYes it does.\n\nRegards James."</span>;
template.sendBodyAndHeaders(<span class="code-quote">"smtp:<span class="code-comment">//davsclaus@apache.org"</span>, body, map);</span>
</pre>
</div></div>

<h3><a name="Mail-Headerstakeprecedenceoverpreconfiguredrecipients"></a>Headers take precedence over pre-configured recipients</h3>

<p>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.</p>

<p>In the sample code below, the email message is sent to <tt>davsclaus@apache.org</tt>, because it takes precedence over the pre-configured recipient, <tt>info@mycompany.com</tt>. Any <tt>CC</tt> and <tt>BCC</tt> 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 <em>either</em> 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.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; headers = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
        headers.put(<span class="code-quote">"to"</span>, <span class="code-quote">"davsclaus@apache.org"</span>);

        template.sendBodyAndHeaders(<span class="code-quote">"smtp:<span class="code-comment">//admin@localhost?to=info@mycompany.com"</span>, <span class="code-quote">"Hello World"</span>, headers);</span>
</pre>
</div></div>

<h3><a name="Mail-Multiplerecipientsforeasierconfiguration"></a>Multiple recipients for easier configuration</h3>

<p>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:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
        Map&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt; headers = <span class="code-keyword">new</span> HashMap&lt;<span class="code-object">String</span>, <span class="code-object">Object</span>&gt;();
        headers.put(<span class="code-quote">"to"</span>, <span class="code-quote">"davsclaus@apache.org ; jstrachan@apache.org ; ningjiang@apache.org"</span>);
</pre>
</div></div>

<p>The preceding example uses a semicolon, <tt>;</tt>, as the separator character.</p>

<h3><a name="Mail-Settingsendernameandemail"></a>Setting sender name and email</h3>

<p>You can specify recipients in the format, <tt>name &lt;email&gt;</tt>, to include both the name and the email address of the recipient.</p>

<p>For example, you define the following headers on the a <a href="/confluence/display/CAMEL/Message" title="Message">Message</a>:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
Map headers = <span class="code-keyword">new</span> HashMap();
map.put(<span class="code-quote">"To"</span>, <span class="code-quote">"Claus Ibsen &lt;davsclaus@apache.org&gt;"</span>);
map.put(<span class="code-quote">"From"</span>, <span class="code-quote">"James Strachan &lt;jstrachan@apache.org&gt;"</span>);
map.put(<span class="code-quote">"Subject"</span>, <span class="code-quote">"Camel is cool"</span>);
</pre>
</div></div>

<h3><a name="Mail-SUNJavaMail"></a>SUN JavaMail</h3>

<p><a href="http://java.sun.com/products/javamail/" class="external-link" rel="nofollow">SUN JavaMail</a> is used under the hood for consuming and producing mails.<br/>
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.</p>
<ul class="alternate" type="square">
	<li><a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/pop3/package-summary.html" class="external-link" rel="nofollow">SUN POP3 API</a></li>
	<li><a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/package-summary.html" class="external-link" rel="nofollow">SUN IMAP API</a></li>
	<li>And generally about the <a href="http://java.sun.com/products/javamail/javadocs/javax/mail/Flags.html" class="external-link" rel="nofollow">MAIL Flags</a></li>
</ul>


<h3><a name="Mail-Samples"></a>Samples</h3>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"jms:<span class="code-comment">//queue:subscription"</span>).to(<span class="code-quote">"smtp://admin@mymailserver.com?password=secret"</span>);</span>
</pre>
</div></div>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from("imap:<span class="code-comment">//admin@mymailserver.com
</span>     password=secret&amp;unseen=<span class="code-keyword">true</span>&amp;consumer.delay=60000")
    .to(<span class="code-quote">"seda:<span class="code-comment">//mails"</span>);</span>
</pre>
</div></div>

<p>In this sample we want to send a mail to multiple recipients: </p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java"><span class="code-comment">// all the recipients of <span class="code-keyword">this</span> mail are:
</span><span class="code-comment">// To: camel@riders.org , easy@riders.org
</span><span class="code-comment">// CC: me@you.org
</span><span class="code-comment">// BCC: someone@somewhere.org
</span><span class="code-object">String</span> recipients = <span class="code-quote">"&amp;To=camel@riders.org,easy@riders.org&amp;CC=me@you.org&amp;BCC=someone@somewhere.org"</span>;

from(<span class="code-quote">"direct:a"</span>).to(<span class="code-quote">"smtp:<span class="code-comment">//you@mymailserver.com?password=secret&amp;From=you@apache.org"</span> + recipients);</span>
</pre>
</div></div>

<h3><a name="Mail-Sendingmailwithattachmentsample"></a>Sending mail with attachment sample</h3>

<div class='panelMacro'><table class='warningMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/confluence/images/icons/emoticons/forbidden.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td><b>Attachments are not support by all Camel components</b><br />The <em>Attachments API</em> 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.</td></tr></table></div>

<p>The mail component supports attachments. In the sample below, we send a mail message containing a plain text message with a logo file attachment.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// create an exchange with a normal body and attachment to be produced as email
</span>Endpoint endpoint = context.getEndpoint(<span class="code-quote">"smtp:<span class="code-comment">//james@mymailserver.com?password=secret"</span>);
</span>
<span class="code-comment">// create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
</span>Exchange exchange = endpoint.createExchange();
Message in = exchange.getIn();
in.setBody(<span class="code-quote">"Hello World"</span>);
in.addAttachment(<span class="code-quote">"logo.jpeg"</span>, <span class="code-keyword">new</span> DataHandler(<span class="code-keyword">new</span> FileDataSource(<span class="code-quote">"src/test/data/logo.jpeg"</span>)));

<span class="code-comment">// create a producer that can produce the exchange (= send the mail)
</span>Producer producer = endpoint.createProducer();
<span class="code-comment">// start the producer
</span>producer.start();
<span class="code-comment">// and let it go (processes the exchange by sending the email)
</span>producer.process(exchange);

</pre>
</div></div>

<h3><a name="Mail-SSLsample"></a>SSL sample</h3>

<p>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.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"imaps:<span class="code-comment">//imap.gmail.com?username=YOUR_USERNAME@gmail.com&amp;password=YOUR_PASSWORD"</span>
</span>    + <span class="code-quote">"&amp;delete=<span class="code-keyword">false</span>&amp;unseen=<span class="code-keyword">true</span>&amp;consumer.delay=60000"</span>).to(<span class="code-quote">"log:newmail"</span>);
</pre>
</div></div>

<p>The preceding route polls the Google mail inbox for new mails once every minute and logs the received messages to the <tt>newmail</tt> logger category.<br/>
Running the sample with <tt>DEBUG</tt> logging enabled, we can monitor the progress in the logs:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
2008-05-08 06:32:09,640 DEBUG MailConsumer - Connecting to MailStore imaps<span class="code-comment">//imap.gmail.com:993 (SSL enabled), folder=INBOX
</span>2008-05-08 06:32:11,203 DEBUG MailConsumer - Polling mailfolder: imaps<span class="code-comment">//imap.gmail.com:993 (SSL enabled), folder=INBOX
</span>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 &lt;007@mi5.co.uk&gt;], to=YOUR_USERNAME@gmail.com], subject=[...
2008-05-08 06:32:12,187 INFO  newmail - Exchange[MailMessage: messageNumber=[332], from=[James Bond &lt;007@mi5.co.uk&gt;], to=YOUR_USERNAME@gmail.com], subject=[...
</pre>
</div></div>

<h3><a name="Mail-Consumingmailswithattachmentsample"></a>Consuming mails with attachment sample</h3>

<p>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:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"imaps:<span class="code-comment">//imap.gmail.com?username=YOUR_USERNAME@gmail.com&amp;password=YOUR_PASSWORD"</span>
</span>    + <span class="code-quote">"&amp;delete=<span class="code-keyword">false</span>&amp;unseen=<span class="code-keyword">true</span>&amp;consumer.delay=60000"</span>).process(<span class="code-keyword">new</span> MyMailProcessor());
</pre>
</div></div>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
    <span class="code-keyword">public</span> void process(Exchange exchange) <span class="code-keyword">throws</span> Exception {
        <span class="code-comment">// the API is a bit clunky so we need to loop
</span>        Map&lt;<span class="code-object">String</span>, DataHandler&gt; attachments = exchange.getIn().getAttachments();
        <span class="code-keyword">if</span> (attachments.size() &gt; 0) {
            <span class="code-keyword">for</span> (<span class="code-object">String</span> name : attachments.keySet()) {
                DataHandler dh = attachments.get(name);
                <span class="code-comment">// get the file name
</span>                <span class="code-object">String</span> filename = dh.getName();

                <span class="code-comment">// get the content and convert it to <span class="code-object">byte</span>[]
</span>                <span class="code-object">byte</span>[] data = exchange.getContext().getTypeConverter()
                                  .convertTo(<span class="code-object">byte</span>[].class, dh.getInputStream());

                <span class="code-comment">// write the data to a file
</span>                FileOutputStream out = <span class="code-keyword">new</span> FileOutputStream(filename);
                out.write(data);
                out.flush();
                out.close();
            }
        }
   }
</pre>
</div></div>
<p>As you can see the API to handle attachments is a bit clunky but it's there so you can get the <tt>javax.activation.DataHandler</tt> so you can handle the attachments using standard API.</p>

<h3><a name="Mail-Howtosplitamailmessagewithattachments"></a>How to split a mail message with attachments</h3>

<p>In this example we consume mail messages which may have a number of attachments. What we want to do is to use the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> EIP per individual attachment, to process the attachments separately. For example if the mail message has 5 attachments, we want the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> to process five messages, each having a single attachment. To do this we need to provide a custom <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> to the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> where we provide a List&lt;Message&gt; that contains the five messages with the single attachment.</p>

<p>The code is provided out of the box in Camel 2.10 onwards in the <tt>camel-mail</tt> component. The code is in the class: <tt>org.apache.camel.component.mail.SplitAttachmentsExpression</tt>, which you can find the source code <a href="https://svn.apache.org/repos/asf/camel/trunk/components/camel-mail/src/main/java/org/apache/camel/component/mail/SplitAttachmentsExpression.java" class="external-link" rel="nofollow">here</a></p>

<p>In the Camel route you then need to use this <a href="/confluence/display/CAMEL/Expression" title="Expression">Expression</a> in the route as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">from(<span class="code-quote">"pop3:<span class="code-comment">//james@mymailserver.com?password=secret&amp;consumer.delay=1000"</span>)
</span>    .to(<span class="code-quote">"log:email"</span>)
    <span class="code-comment">// use the SplitAttachmentsExpression which will split the message per attachment
</span>    .split(<span class="code-keyword">new</span> SplitAttachmentsExpression())
        <span class="code-comment">// each message going to <span class="code-keyword">this</span> mock has a single attachment
</span>        .to(<span class="code-quote">"mock:split"</span>)
    .end();
</pre>
</div></div>

<p>If you use XML DSL then you need to declare a method call expression in the <a href="/confluence/display/CAMEL/Splitter" title="Splitter">Splitter</a> as shown below</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;split&gt;</span>
  <span class="code-tag">&lt;method beanType=<span class="code-quote">"org.apache.camel.component.mail.SplitAttachmentsExpression"</span>/&gt;</span>
  <span class="code-tag">&lt;to uri=<span class="code-quote">"mock:split"</span>/&gt;</span>
<span class="code-tag">&lt;/split&gt;</span>
</pre>
</div></div>


<h3><a name="Mail-UsingcustomSearchTerm"></a>Using custom SearchTerm</h3>
<p><b>Available as of Camel 2.11</b></p>

<p>You can configure a <tt>searchTerm</tt> on the <tt>MailEndpoint</tt> which allows you to filter out unwanted mails. </p>

<p>For example to filter mails to contain Camel in either Subject or Text you can do as follows:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"imaps://mymailseerver?username=foo&amp;password=secret&amp;searchTerm.subjectOrBody=Camel"</span>/&gt;</span>
  <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:myBean"</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

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

<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> unseen </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Whether to limit by unseen mails only. </td>
</tr>
<tr>
<td class='confluenceTd'> subjectOrBody </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To limit by subject or body to contain the word. </td>
</tr>
<tr>
<td class='confluenceTd'> subject </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The subject must contain the word. </td>
</tr>
<tr>
<td class='confluenceTd'> body </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The body must contain the word. </td>
</tr>
<tr>
<td class='confluenceTd'> from </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The mail must be from a given email pattern. </td>
</tr>
<tr>
<td class='confluenceTd'> to </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The mail must be to a given email pattern. </td>
</tr>
<tr>
<td class='confluenceTd'> fromSentDate </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The mail must be sent after or equals (GE) a given date. The date pattern is <tt>yyyy-MM-dd HH:mm:SS</tt>, eg use <tt>"2012-01-01 00:00:00"</tt> to be from the year 2012 onwards. You can use <tt>"now"</tt> for current timestamp. </td>
</tr>
<tr>
<td class='confluenceTd'> toSentDate </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> The mail must be sent before or equals (BE) a given date. The date pattern is <tt>yyyy-MM-dd HH:mm:SS</tt>, eg use <tt>"2012-01-01 00:00:00"</tt> to be before the year 2012. You can use <tt>"now"</tt> for current timestamp. </td>
</tr>
</tbody></table>
</div>
</div>

<p>The <tt>SimpleSearchTerm</tt> is designed to be easily configurable from a POJO, so you can also configure it using a &lt;bean&gt; style in XML</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;bean id=<span class="code-quote">"mySearchTerm"</span> class=<span class="code-quote">"org.apache.camel.component.mail.SimpleSearchTerm"</span>&gt;
  &lt;property name=<span class="code-quote">"subject"</span> value=<span class="code-quote">"Order"</span>/&gt;
  &lt;property name=<span class="code-quote">"to"</span> value=<span class="code-quote">"acme-order@acme.com"</span>/&gt;
  &lt;property name=<span class="code-quote">"fromSentDate"</span> value=<span class="code-quote">"now"</span>/&gt;
 &lt;/bean&gt;
</pre>
</div></div>

<p>You can then refer to this bean, using #beanId in your Camel route as shown:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
<span class="code-tag">&lt;route&gt;</span>
  <span class="code-tag">&lt;from uri=<span class="code-quote">"imaps://mymailseerver?username=foo&amp;password=secret&amp;searchTerm=#mySearchTerm"</span>/&gt;</span>
  <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:myBean"</span>/&gt;</span>
<span class="code-tag">&lt;/route&gt;</span>
</pre>
</div></div>

<p>In Java there is a builder class to build compound <tt>SearchTerm}}s using the {{org.apache.camel.component.mail.SearchTermBuilder</tt> class.<br/>
This allows you to build complex terms such as:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-comment">// we just want the unseen mails which is not spam
</span>SearchTermBuilder builder = <span class="code-keyword">new</span> SearchTermBuilder();

builder.unseen().body(Op.not, <span class="code-quote">"Spam"</span>).subject(Op.not, <span class="code-quote">"Spam"</span>)
  <span class="code-comment">// which was sent from either foo or bar
</span>  .from(<span class="code-quote">"foo@somewhere.com"</span>).from(Op.or, <span class="code-quote">"bar@somewhere.com"</span>);
  <span class="code-comment">// .. and we could <span class="code-keyword">continue</span> building the terms
</span>
SearchTerm term = builder.build();
</pre>
</div></div>

<h3><a name="Mail-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting Started</a></li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Mail">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=52932&revisedVersion=93&originalVersion=92">View Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Mail?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message