Triggering an OSB Message Flow with Email

Often in our business processes/integrations we might have a situation where in we would need to trigger our message flow/process with an Email.

With OSB’s Email transport listening to a mailbox and triggering a message flow is very simple and comes out of the box.

The following article will explain as a tutorial how can this be achieved.


The prerequisites for this tutorial are as under :

  1. Oracle Service Bus 11g (Link)
  2. Apache James Server (Link) that can act as a Mail server.

Getting Started

Setting Up Apache James

The first thing to get started would be to download the Apache James binary from here. Apache James would act as the email server through which we can send/receive emails.

Copy the James binary at any location on your computer. The binaries would come with a bin folder. Navigate to the bin folder to locate the run.bat file.

Apache James need JDK 1.5 and above so make sure JAVA_HOME is added with the JDK directory in the list of environment variables before running James.

Open a command prompt and run the run.bat file.

We can now see that Apache James server is up and running. Pretty simple.


Next we can verify by doing a telnet to the James Management port i.e. 4555. Login to James using the default Login Id and Password.

Login Id: root
Password: root

We can add user inboxes by the following command

adduser <username> <password>

After you add users the next thing you can do to verify this is use the command listusers that  will give you all users in the server.


Having done this we are good with the email server part. By default James runs both the SMTP server to send mail and a POP3 server that can be used to retrieve mails.

Creating the OSB Message Flow

The next thing would be to create a Message flow in OSB that can be triggered with the Email event.

Make sure that Oracle Service Bus domain is created and a server is up and running.

Open http:host:port/sbconsole and login with the username and password configured for the OSB domain.

The first step would be to create a SMTP server configuration. This is required as we would create a dummy Business Service to post a message to the configured inbox.

Once you have logged in to the OSB console go to System Administration –> SMTP Servers –> Add and create a SMTP server as under


Click on Save to save the configuration.

Now go to project explorer and create a project and name it EmailSub. Create an XML Schema resource from the Create Resource Icon based on the following XSD.

<xsd:schema xmlns:xsd="" elementFormDefault="qualified"
attributeFormDefault="unqualified" targetNamespace=""
<xsd:complexType name="ContentType">
<xsd:element name="MimeType" type="xsd:string" default="text/plain" minOccurs="0"/>
<xsd:element name="ContentBody" type="sales:OrderIndicatorType"/>
<xsd:element name="ContentEncoding" type="xsd:string" nillable="true"/>
<xsd:complexType name="EmailPayloadType">
<xsd:element name="FromAccountName" type="xsd:string" minOccurs="0"/>
<xsd:element name="To" type="xsd:string" minOccurs="0"/>
<xsd:element name="ReplyToAddress" type="xsd:string" minOccurs="0"/>
<xsd:element name="Subject" type="xsd:string"/>
<xsd:element name="Content" type="sales:ContentType"/>
<xsd:element name="Cc" type="xsd:string" minOccurs="0"/>
<xsd:element name="Bcc" type="xsd:string" minOccurs="0"/>
<xsd:complexType name="OrderIndicatorType">
<xsd:element name="OrderID" type="xsd:string" minOccurs="0"/>
<xsd:element name="OrderAmount" type="xsd:string" minOccurs="0"/>
<xsd:element name="CustomerID" type="xsd:string" minOccurs="0"/>
<xsd:element name="QuoteID" type="xsd:string"/>
<xsd:element name="BusinessUnitID" type="xsd:string"/>
<xsd:element name="EmailPayload" type="sales:EmailPayloadType"/>

Create a Business Service based on Messaging Service Type called SendEmailBS


Configure rest of the service as under


Save the service and activate the session. Test the business service that we just created. Also configure an email client to see whether you get this email.

Here is a test payload

<sal:EmailPayload xmlns:sal="">

Off course this is a very basic way of testing. You can also go on and create a front ending proxy service to pass the content payload, subject and other email headers dynamically.


For the second part we need to configure a Proxy Service that can poll this mail box and instantiate its message flow whenever an email arrives.

The first step for this would be to configure a Service Account of Type ‘Static’ that will basically have the user name and password for the mail box.


We would need to attach this Service Account while configuring the Proxy Service required to poll this mail box.

Next create a Messaging type Proxy Service based on the same Email.xsd as under



Lastly go and edit the Proxy Service Message Flow. Add a Pipeline Pair and in the Request Pipeline add a Stage.

Add some simple action to extract the payload from the body variable and log the body to validate whether we receive an email.


Well we are now almost done.

Use the dummy Business Service that we created and push one more message to the user Inbox. This time you will notice that the Proxy Service picks up the message and logs it to the server log.

Open the domain AdminServer.log file to see the message getting logged.


That is pretty much it. Now you can create your own message flow that can be executed with the trigger of an Email.

One thought on “Triggering an OSB Message Flow with Email

  1. I am wokring on OSB project where in message flow I need to read the mail and iterate over the attachments.

    I am using following expression

    we have Upgraded OSB from 9 to 10g R3

    for Each variable [x] in ./ctx:attachment/ctx:body/ctx:binary-content/@ref of variables fileAttachments

    Buts its not coming in side the loop

    I printed my attachment variable.

    text/plain; name=”20121118130513.txt”
    attachment; filename=”loadshed20121118130513.txt”;
    size=1379; creation-date=”Sat, 18 Aug 2012 02:42:11 GMT”;
    modification-date=”Sat, 18 Aug 2012 03:30:15 GMT”
    FNAM 20121118130513.txt

    Please help me and suggest


If you have any comments, suggestions or feedback about the post, please feel free to type it here and I will do my best to address them asap

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s