Wednesday Apr 04, 2007

Receiving Emails through SMTP BC.

As soon as you see this topic you may think that using SMTP BC you can receive emails as you receive emails in your Inbox. But the case is different here. Using SMTP BC, you can receive email which is destined for your SMTP BC and process the email based on the content.

SMTP BC is Simple Mail Transfer Protocol, which means that this is a protocol defined in RFC 821 for the mail servers defining a standard way to handle the emails. It is also a protocol for communicating with SMTP Servers for email exchanges. So, In a typical scenario when an SMTP Server receives an email it may handle in the following ways:

  •  Check if the destination email ids in the emails are bound to this SMTP Server. If so, store the emails in a location where the email clients can access it.
  •  If the destination email ids are not bound to this email address, but the SMTP Server knows how to route the email to the destination, then reroute the email to the destination.
  •  If it cannot recognize the email id defined, return an error.

Coming back to the SMTP BC case, How is it going to receive the email? Is it going to read it from a mail box? No.

 SMTP BC is implemented in such a way that it will listen in a port (default is 25) specified in the WSDL for incoming emails. That is, it has a built in SMTP Server capability to receive emails. So, what will it do receiving email? Well it just provides the email content to the consumers of the Jbi ecosystem.

As I said, an SMTP Server has to recognize the email ids mentioned in the to,cc,bcc section of an email. But how does the SMTP BC's server recognize the email ids? In a typical scenario, an SMTP Server will have a huge database of email addresses belonging to the domain. But in our case, the SMTP BC recognizes only the email ids defined in the mailto: URL of WSDL extension's smtp:server tag's location attribute.

For eg:

     <wsdl:service name="smtpWSDLService">
        <wsdl:port name="smtpWSDLPort" binding="tns:smtpWSDLBinding">
            <smtp:address location=","/>

The above WSDL defines two email ids: and In this case, the SMTP BC's smtp server can accept emails destined for only these two email ids. If you use your email client to send emails to this smtp server with to ,cc or bcc having any other email ids, the SMTP BC will reject the email.

Here are some of the scenarios I can think of where SMTP BC's inbound case can be helpful.

  1. You want to receive an email, store it somewhere and send an acknowledgement email to the sender.
  2. You want to parse an email which is in a specified format you know and process it. 
  3. Based on the subject of the email you want to organize the emails or forward it to some other email ids.

A demo:

The below demo is a simple scenario where the content and subject of an email is preserved in a file.

Here are the Steps involved:

  1. Create a BPEL Module.
  2. Create a WSDL with SMTP Binding.
  3. Create a WSDL with File Binding.
  4. Create a BPEl process.
  5. Using BPEL Designer draw the flow of activities.
  6. Create a Composite Application project.
  7. Add the Bpel Module to the Composite Application.
  8. Compile and deploy the application.
  9. Use an email client and configure the SMTP server to the SMTP BCs smtp server.
  10. Send an email with to address specified in the WSDL.

You should be able to see the file containg the subject and the content. Here is the demo:

Tuesday Mar 13, 2007

Using SMTP BC to send Email in JBI Environment

What is SMTP BC?

Java Business Integration (JBI) is a standard for integrating business sytems. It defines a platform for different components to interact each other in a standard way. A binding component in a JBI environment is a piece of software written to interact with external systems which typically involves communicating through a specific protocol. Thus SMTP Binding component provides communication to SMTP servers for other JBI components.

How do you send e-mail using SMTP BC?

The SMTP BC currently provides mechanism for sending emails to SMTP servers and it also acts as a SMTP server to receive emails. Here we will see how it helps us to send emails. Here we use NetBeans 5.5.1 IDE to develop a composite application which uses SMTP BC, BPEL SE and HTTP BC to send a mail.

Sample Application:

The sample application we create here involes a http request triggering an email to be sent to a particular email destination. The steps to create are:

  1. Create a BPEL Module project

  2. Create 2 WSDLs. one with Http/SOAP Binding and another with SMTP Binding.

  3. Edit the WSDL with SMTP Binding to specify the destination email address, SMTP Server to use and the message part for content of the email.

  4. Create a BPEL Process.

  5. Build the module to create a Service Unit.

  6. Create a Composite Application.

  7. Add the above BPEL Module to the composite application.

  8. Build the Composite Application to a Service Assembly.

  9. Start the App.Server and deploy the composite application.

  10. Test the application.

How to Create the WSDL With SMTP Binding:

Here we will use the WSDL Wizard for creating the WSDLs:

1. In the BPEL Module Project, Right Click on Process Files folder and select New - > File/Folder. Select the Folder XML and then WSDL Document from Right pane.

2. Provide a Name for WSDL. In this sample, we are not going to use any Schemas, so leave it as blank. Click Next.

3. Select the Operation type as One-Way Operation. And leave the other values to default. Click Next.

4. Select SMTP Binding in the "Concrete Configuration" Screen. Click Finish.

Providing values for smtp:address :

1. Open the SMTPWSDL using WSDL Editor
2. Expand the folder: Services -> SMTPWSDLService -> SMTPWSDLPort -> smtp:address
3. Provide the values in property editor for location and smtpserver attributes.

Providing values for smtp:input :

1. Open the SMTPWSDL using WSDL Editor.
2. Expand the folder : Bindings -> SMTPWSDLBinding -> SMTPWSDLOperation -> input1 -> smtp:input.
3. Provide the value in property editor for message. eg: part1.

Creating the WSDL With Http Binding:

You can use the WSDL Wizard for creating the WSDL same as SMTP Binding except these changes:

    - Select Request-Response Operation in 3rd Step.
    - Select Binding Type to SOAP and Binding SubType to RPC Literal.

Creating the BPEL process:

1. Right Click on Process Files folder and select New -> BPEL Process.
2. Provide Name for the bpel process and click on Finish
3. Using the BPEl Editor / BPEL Mapper, create the bpel with these activities:
    - Receive Operation on HTTP
    - Assign the request received to the request for SMTP Invoke.
    - Invoke operation on SMTP
    - Assign a static String "Email Sent Successfully"
    - Reply Operation on HTTP.

The completed BPEL module will look like this:

Creating the Composite Application:

1. Create a new Project. Select Service Oriented Architecture -> Composite Application.

2. Provide a name for the project and click finish

3. Under the Jbi project. Right click on JBI Modules and select Add JBI Module. Find the above created BPEl project and add it.

Building and deploying the SA:

1. Right click the Comp. App. project and select Build.

2. In the Runtime tab, make sure the Application Server is started.

3. Right click the Comp. App. project and select Deploy.

Testing the application.
To Create a TestCase:

In the Comp. App. project,

1. Right Click on the Test Folder and select New Test Case
2. Provide a TestCase name and go to next screen.
3. Choose the WSDL implementing HTTP/SOAP Binding and click next.

4. Select the Operation you want to test and Click Finish

A test case would have got created with an Input.xml and output.xml. Edit the input.xml to provide the data.

Running the Test Case:

Run the Testcase by Right click on the testcase and select Run.

The First time it fails, because the output.xml is empty and it does not matches with the output returned. To make the output returned as a valid output, right click on the output returned (marked as Failed) and select "Use as Output"




« July 2016