Let see how to configure the InputEmailAdapter and get a email body through that.
- Extract thhe WSO2 BAM 2.5.0 pack.
- Enable the mail transport receiver in Axis2 level by uncommenting the following line in <PRODUCT_HOME>/repository/conf/axi2/axis2.xml file
<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.MailTransportListener"/>
- Since we are going to handle plain text messages you need to add the following message builder to axis2.xml file MessageBuilders section
- Then you can follows the steps upto "Configuring input email event adapter" mentioned in the doc[1] to configure the email adapter.
- Then go to Event Streams section Management Console -> Main -> Event Streams
- Click Add Event Stream. Fill the information similar to below image
- When you select Add, it will asked to select Event Builder for the newly created stream.
- Select Custom Event Builder from that
- It will show a window to configure the Builder. Put some name for the builder and select adapter that you already configured in step 2 from the Input Event Adaptor Name list. Put some name to email service name. Npte that When you set the email service name, the email subject should be SOAPAction:urn:<email_service_name>. Select text as the input mapping type and click add event builder
- Then go to the Event Streams window again and you will see your newly created stream
- Click In-Flows in the newly created stream
- There you will see your email event builder is added to the in flow of the stream
- Click Edit button of that builder
- By default you will see custom mapping is disabled as below
<mapping customMapping="disable" type="wso2event"/>
Change that as follows - Click update.
- Now send an email with the subject as SOAPAction:urn:<email_service_name> to the email address that you configured with the body as <tag>This is my email Body</tag>
- If everything is successfully configured you should be able to see the email body through the Cassandra Explorer as below
<messageBuilder contentType="text/plain" class="org.apache.axis2.format.PlainTextBuilder"/>
<mapping customMapping="enable" type="text">
<property>
<from regex="<tag>(.+?)</tag>"/><!--I'm going to take the message between tags in my email body-->
<to name="email_body" type="string"/><!--here name is the event attribute that we put when creating the stream-->
</property>
</mapping>
[1] - https://docs.wso2.com/display/BAM250/Input+Email+Event+Adapter
[2] - http://wso2.com/library/articles/2013/08/writing-custom-event-adaptors-for-cep-3.0.0/
[3] - https://docs.wso2.com/pages/viewpage.action?pageId=34605846
good article, i can't imagine why need to go through so much trouble just to access a body of an email. Development languages and frameworks support to be efficient and make developers productive. Anything other than
ReplyDeleteimport parserLib;
let text = email;
let body = parserLib.getBody(text);
is overkill IMHO :)