...
The ServiceMix Mail component provides support for receiving and sending mails via the enterprise service bus.
Note |
---|
|
Note that this component is only available in releases >= 3.3. |
Installation
Installing the servicemix-mail component can be done in several ways:
- drop the installer zip in an hotdeploy directory monitored by ServiceMix
- using ant tasks
Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console.
Creation
You can use Maven to create a service unit.
Maven Archetype
You can use Maven servicemix-mail-service-unit archetype to create a service unit:
Code Block |
---|
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-mail-service-unit \
-DarchetypeVersion=2010.01 \
-DgroupId=your.group.id |
Code Block |
---|
mvn archetype:create \
-DarchetypeGroupIdDartifactId=orgyour.apacheartifact.servicemix.toolingid \
-DarchetypeArtifactIdDversion=servicemix-mail-service-unit \
your-version
|
Endpoints Configuration
Poller Endpoint (Consumer)
Code Block |
---|
lang | xml |
---|
title | Polling (Consumer) Endpoint |
---|
|
<mail:poller service="test:myMailService"
-DgroupId=com.mycompany.myproduct \
-DartifactId=mycomponent.artifact
|
Cookbook recipes
Children Display |
---|
page | SM:servicemix-mail cookbook |
---|
excerpt | true |
---|
excerptType | simple |
---|
|
Endpoints
Code Block |
---|
lang | xml |
---|
title | Sender (provider) endpoint |
---|
|
<mail:sender service="test:myMailService" endpoint="pollerEndpoint"
endpointtargetService="senderEndpointtest:myMailProcessor"
senderperiod="no-reply@servicemix.org10000"
receiverconnection="testreceiver@targethost.comimap://user@testserver:143/INBOX?password=myPass"
connectiondeleteProcessedMessages="smtp://lhein@testserver?password=myPass"false"
processOnlyUnseenMessages="true" />
|
Code Block |
lang
Note |
---|
xml | title | Polling (consumer) endpoint |
---|
|
<mail:poller service="test:myMailService"
endpoint="pollerEndpoint"
targetService="test:myMailProcessor"
period="10000"
connection="imap://lhein@testserver:143/INBOX?password=myPass"
deleteProcessedMessages="false"
processOnlyUnseenMessages="true" />
|
Consumer Endpoint (Polling)
Note |
---|
title | Message Exchange Pattern |
---|
|
The poller endpoint will only generate InOnly exchanges. |
The following table shows the additional configuration possibilities of the endpoint other than the configuration of the default PollingEndpoint class.
Info |
---|
title | Poller endpoint attributes |
---|
borderStyle | solidbgColor='lighblue' |
---|
|
Name | Type | Description | Default |
---|
connection | string | sets the connection information | null (must be spec'd) | deleteProcessedMessages | boolean | delete mail from server when it is processed | false | processOnlyUnseenMessages | boolean | process only mails which are new (unseen) | true | marshaler | class | org.apache.servicemix.mail.marshaler.AbstractMailMarshaler | DefaultMailMarshaler | maxFetchSize | int | sets max amount of mails to fetch, -1 means no limit | -1 | debugMode | boolean | sets the debug mode for the javamail api | false | customTrustManagers | string | sets one or more custom trust managers for use with ssl | null | storage | class | sets the storage to use for remembering the seen messages when using pop protocol (org.apache.servicemix.store.Store) | null | customProperties | java.util.Map | a map of custom properties for the connection | null |
|
Warning |
---|
|
The attribute "customProperties" is available in version 2008.02 and above only! |
The DefaultMailMarshaler (used if no other is set) will convert in the following way:
- Headers of the mail are copied 1:1 into the message properties (and concatenated if needed)
- if the mail has only plain text, the content will be put to property MSG_TAG_TEXT and to the message content
- if the mail has only html, the content will be put to property MSG_TAG_HTML and to the message content
- if the mail has both plain text and html, then both will be put to the right property and the content of the message will be the plain text
- attachments are copied 1:1 from mail to message
The connection uri
The connection uri has to be specified in the following way:
No Format |
---|
Template: <protocol>://<user>@<host>[:<port>][/<folder>]?password=<password>
OR
Template: <protocol>://<host>[:<port>][/<folder>]?user=<user>;password=<password>
Example:
imap://lhein@imapserver:143/INBOX?password=mypass
pop3://pop3server/INBOX?user=me@myhome.org;password=mypass
|
Info |
---|
title | Poller endpoint attributes |
---|
borderStyle | solidbgColor='lighblue' |
---|
|
Name | Description |
---|
protocol | the protocol to use (example: pop3 or imap) | user | the user name used to log into an account | host | the name or ip address of the mail server | port | the port number to use (optional) | folder | the folder to poll from (optional) | password | the password for the login |
|
Provider Endpoint (Sending)
The following table shows the configuration possibilities of the endpoint.
|
The poller endpoint will only generate InOnly exchanges. |
Info |
---|
title | Poller Endpoint Attributes |
---|
borderStyle | solidbgColor='lighblue' |
---|
|
Name | Type | Description | Default |
---|
connection | string | sets the connection information | null (must be spec'd) | deleteProcessedMessages | boolean | delete mail from server when it is processed | false | processOnlyUnseenMessages | boolean | process only mails which are new (unseen) | true | marshaler | class | org.apache.servicemix.mail.marshaler.AbstractMailMarshaler | DefaultMailMarshaler | maxFetchSize | int | sets max amount of mails to fetch, -1 means no limit | -1 | debugMode | boolean | sets the debug mode for the javamail api | false | customTrustManagers | string | sets one or more custom trust managers for use with ssl | null | storage | class | sets the storage to use for remembering the seen messages when using pop protocol (org.apache.servicemix.store.Store) | null | customProperties | java.util.Map | a map of custom properties for the connection | null |
|
The DefaultMailMarshaler (used if no other is set) will convert in the following way:
- Headers of the mail are copied 1:1 into the message properties (and concatenated if needed)
- if the mail has only plain text, the content will be put to property MSG_TAG_TEXT and to the message content
- if the mail has only html, the content will be put to property MSG_TAG_HTML and to the message content
- if the mail has both plain text and html, then both will be put to the right property and the content of the message will be the plain text
- attachments are copied 1:1 from mail to message
The connection URI
The connection uri has to be specified in the following way:
No Format |
---|
Template: <protocol>://<user>@<host>[:<port>][/<folder>]?password=<password>
OR
Template: <protocol>://<host>[:<port>][/<folder>]?user=<user>;password=<password>
Example:
imap://user@imapserver:143/INBOX?password=mypass
pop3://pop3server/INBOX?user=me@myhome.org;password=mypass
|
Info |
---|
title | URI Attributes |
---|
borderStyle | solidbgColor='lighblue' |
---|
|
Name | Description |
---|
protocol | the protocol to use (example: pop3 or imap) | user | the user name used to log into an account | host | the name or ip address of the mail server | port | the port number to use (optional) | folder | the folder to poll from (optional) | password | the password for the login |
|
Sender Endpoint (Provider)
Code Block |
---|
lang | xml |
---|
title | Sender (provider) endpoint |
---|
|
<mail:sender service="test:myMailService"
endpoint="senderEndpoint"
sender="no-reply@servicemix.org"
receiver="testreceiver@targethost.com"
connection="smtp://lhein@testserver?password=myPass" />
|
Info |
---|
title | Sender Endpoint Attributes |
---|
|
Info |
---|
title | Sender endpoint attributes |
---|
borderStyle | solidbgColor='lighblue' |
---|
|
Name | Type | Description | Default |
---|
connection | string | sets the connection information | null (must be spec'd) | sender | string | defines the sender address of the mail | no-reply@localhost | receiver | string | defines the receiver address of the mail | null | marshaler | class | org.apache.servicemix.mail.marshaler.AbstractMailMarshaler | DefaultMailMarshaler | debugMode | boolean | sets the debug mode for the javamail api | false | ignoreMessageProperties | java.util.List | a list of properties of the IN message which will be ignored | false | customProperties | java.util.Map | a map of custom properties for the connection | null | customTrustManagers | string | sets one or more custom trust managers for use with ssl | null |
|
Warning |
---|
title | Version Information |
---|
The
...
The DefaultMailMarshaler (used if no other is set) will convert in the following way:
...
How is the sender determined?
if If there is a preconfigured sender for the endpoint from xbean.xml, it will be used
else if MSG_TAG_FROM is defined in the message properties, then it will be used
else the method getDefaultSender() of the marshaler is invoked
...
Warning |
---|
title | Common pitfall regarding the receiver |
---|
|
If you are just setting up a mail-bridge (means just a poller connected to a sender for mail forwarding) you will need to provide a sender property ignoreMessageProperties as List, containing a list of to ignore message properties. Inside you should at least define the org.apache.servicemix.mail.to value, otherwise the receiver will be the receiver of the original mail. That would just forward the original mail to the account you are polling from generating a nice mail loop. Be warned! |
Cookbook recipes
Children Display |
---|
page | SM:servicemix-mail cookbook |
---|
excerpt | true |
---|
excerptType | simple |
---|
|
How to use customProperties
...