servicemix-mailPage edited by Jean-Baptiste OnofréChanges (36)
Full ContentServiceMix MailThe ServiceMix Mail component provides support for receiving and sending mails via the enterprise service bus. Maven ArchetypeYou can use Maven servicemix-mail-service-unit archetype to create a service unit:
mvn archetype:create \
-DarchetypeGroupId=org.apache.servicemix.tooling \
-DarchetypeArtifactId=servicemix-mail-service-unit \
-DarchetypeVersion=2010.01 \
-DgroupId=your.group.id \
-DartifactId=your.artifact.id \
-Dversion=your-version
The connection URIThe connection uri has to be specified in the following way: Template: <protocol>://<user>@<host>[:<port>][/<folder>]?password=<password> OR Template: <protocol>://<host>[:<port>][/<folder>]?user=<user>;password=<password> Example: imap://u...@imapserver:143/INBOX?password=mypass pop3://pop3server/[email protected];password=mypass
Sender Endpoint (Provider)Sender (provider) endpoint <mail:sender service="test:myMailService" endpoint="senderEndpoint" sender="[email protected]" receiver="[email protected]" connection="smtp://lh...@testserver?password=mypass" />
The DefaultMailMarshaler (used if no other is set) will convert in the following way:
How is the sender determined?If there is a preconfigured sender for the endpoint from xbean.xml, it will be used How is the receiver determined?If there is a TO property in the normalized message, then it will be used.
Cookbook recipes
How to use customPropertiesVia this attribute you can provide a map of properties which will be applied to the connection properties. Doing so enables you to Polling endpoint with ignored TOP headers (same is also for sender) <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:mail="http://servicemix.apache.org/mail/1.0" xmlns:test="http://www.servicemix.org/example" xmlns:util="http://www.springframework.org/schema/util"> <mail:poller service="test:myMailService" endpoint="pollerEndpoint" targetService="test:myMailProcessor" period="10000" connection="imap://lh...@testserver:143/INBOX?password=myPass" deleteProcessedMessages="false" processOnlyUnseenMessages="true" customProperties="#customProps"/> <util:map id="customProps"> <entry key="mail.pop3.forgettopheaders" value="true" /> </util:map> </beans> For a list of properties used by the SUN implementation influencing the connection have a look at the Mail API documentation: How to use ignoreMessagePropertiesVia this property you can provide a list of properties of the normalized in message which will be set to null Sending endpoint with skipping the adress fields <?xml version="1.0" encoding="UTF-8"?> <beans xmlns:mail="http://servicemix.apache.org/mail/1.0" xmlns:test="http://www.servicemix.org/example" xmlns:util="http://www.springframework.org/schema/util"> <mail:sender service="test:myMailService" endpoint="senderEndpoint" sender="[email protected]" receiver="[email protected]" connection="smtp://lh...@testserver?password=mypass" ignoreMessageProperties="#ignoreProps" /> <util:list id="ignoreProps"> <value>org.apache.servicemix.mail.to</value> <value>org.apache.servicemix.mail.cc</value> <value>org.apache.servicemix.mail.bcc</value> <value>org.apache.servicemix.mail.from</value> <value>org.apache.servicemix.mail.replyto</value> </util:list> </beans> For all xbean file endpoint configuration take a look at Xml schemas MarshalersYou can write your own marshalers for conversion between mail and normalized message and vice versa. Subclassing the AbstractMailMarshalerFor 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="[email protected]" connection="imap://lh...@testserver:143?password=myPass" > <property name="marshaler"> <bean class="com.mycompany.MyMailMarshaler" /> </property> </mail:poller> Mapping of headers and propertiesAll 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 AbstractMailMarshaler):
Mail Content TypesThese are the available content types:
On incoming mails you may evaluate this property on the normalized message to find out which kind of mime type the mail had. On outgoing mails you can control the mime type to use for the mail. If you don't set the content type it will be auto-sensed by the marshaler. IMAPS and POP3SIf you want to use secure protocols like IMAPS or POP3S you have several oportunities to do that. The standard wayThe standard way would be to just set the protocol in the connection uri to imaps instead of imap. (same for smtp and pop3) The alternative wayYou have the possibility to write your own TrustManager and let the component use this custom trust manager. If you want no verification of the servers certificate at all then you can use the shipped DummyTrustManager.
How to write a custom trust manager?1. You need to subclass a trust manager which implements the TrustManager interface directly or indirectly. The constructor has to be parameterless. Custom Trust Manager Example <mail:poller service="test:myMailService" endpoint="pollEndpoint" targetService="test:myMailProcessingService" period="10000" connection="imaps://lh...@imapserver/INBOX?password=mypass" deleteProcessedMessages="false" processOnlyUnseenMessages="true" customTrustManagers="org.apache.servicemix.mail.security.DummyTrustManager" /> If you are not using a secure protocol the attribute customTrustManager will be ignored at all. How to debug if I got problems connecting to the mail server?There is a additional attribute you may specify in the endpoints configuration. This attribute is called debugMode and accepts the values "true" or "false". This will switch the JavaMail debug mode on or off providing useful details to you via console or servicemix.log file. Using template enginesNOTHING DONE YET...FEEL FREE TO HELP US OUT HERE.....TODO VelocityNOTHING DONE YET...FEEL FREE TO HELP US OUT HERE.....TODO
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache ServiceMix > servicemix-mail confluence
- [CONF] Apache ServiceMix > servicemix-mail confluence
- [CONF] Apache ServiceMix > servicemix-mail confluence
