You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

ServiceMix Mail

The ServiceMix Mail component provides support for receiving and sending mails via the enterprise service bus.

Availability

Note that this component is only available in releases > 3.2.1.

Endpoints

Sender (provider) endpoint
<mail:sender service="test:myMailService" 
             endpoint="senderEndpoint"
             sender="no-reply@servicemix.org" 
             connection="imap://lhein@testserver:143?password=myPass" /> 
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)

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.

Poller endpoint attributes

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.AMailMarshalerSupport

DefaultMailMarshaler

 
 

The connection uri

The connection uri has to be specified in the following way:

 
Template: <protocol>://<user>@<host>[:<port>][/<folder>]?password=<password>

Example: imap://lhein@imapserver:143/INBOX?password=mypass

Poller endpoint attributes

Name

Description

protocol

the protocol to use (example: pop 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.

Sender endpoint attributes

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

marshaler

class

org.apache.servicemix.mail.marshaler.AMailMarshalerSupport

DefaultMailMarshaler

 
 

For all xbean file endpoint configuration take a look at Xml schemas

Marshalers

You can write your own marshalers for conversion between mail and normalized message and vice versa.
To do this you simply need to subclass the org.apache.servicemix.mail.marshaler.AMailMarshalerSupport or even the
DefaultMailMarshaler if you don't want to start from scratch.

Subclassing the AMailMarshalerSupport

For providing your own marshaler you only need to implement two methods:

convertMailToJBI(...)

This method is responsible for translating a received mail message into a jbi compliant normalized message ready to be sent to the bus.

convertJBIToMail(...)

This method is responsible for translating a received normalized message into a mail message ready to be sent to the mail server.

After finishing your marshaler you can simply configure your endpoints to use it:

Marshaler example
<mail:poller service="test:myMailService" 
             endpoint="senderEndpoint"
             sender="no-reply@servicemix.org" 
             connection="imap://lhein@testserver:143?password=myPass" > 

    <property name="marshaler">
        <bean class="com.mycompany.MyMailMarshaler" />
    </property>

</mail:poller>

Mapping of headers and properties

All mail headers are mapped (nearly) one-to-one into message properties. If there are multiple mail headers with the same name, then the values will be concatenated and separated by the semicolon (;-character).

There are some more important properties which affect the handling of the message / mail (constants are defined in AMailMarshalerSupport):

Special message properties

Key

Description

org.apache.servicemix.mail.to

The address(es) the mail was or will be sent to.

org.apache.servicemix.mail.cc

The addess(es) the mail was or will be sent to as copy.

org.apache.servicemix.mail.bcc

The addess(es) the mail will be sent to as blind copy.

org.apache.servicemix.mail.from

The addess the mail was received from or will be used as sender.

org.apache.servicemix.mail.text

Contains the plain text content of the mail body if existing.

org.apache.servicemix.mail.html

Contains the html content of the mail body if existing.

org.apache.servicemix.mail.subject

The subject of the received mail or for the mail to be sent.

org.apache.servicemix.mail.replyto

The address to be used as reply-to.

org.apache.servicemix.mail.sentdate

The date the email was sent.

org.apache.servicemix.mail.alternativecontent

Contains the alternative content of the mail body.

 
 

  • No labels