Sunday, 18 September 2011

Schedule Email Notification using Oracle BPEL - Part 1

Email notifications are widely used in Oracle Applications for FYI or Action notifications. They can be achieved in many ways using Workflow, PL/SQL, host file etc. As we are all getting geared up for Fusion Middleware, I wanted to explore the option of using BPEL process.

In my article, I will create a bpel process which it scheduled to send email notifications say every 30 min. For simplicity I will do this in two steps which are covered in two articles.

1. Create a bpel process which sends email notification.
2. Schedule the above bpel process to run every 30 min.

This article covers the sending emails using BPEL process. Before I go into the steps of implementing email notification, I will brief you about the environment I'm using for this article.

Environment for this article

  • SOA Suite Basic Installation. So it uses Oracle Lite database.
  • JDeveloper

For setting up the environment, refer to the SOA Suite Installation article.

The problems I've faced during installation are:

  • Internet Explorer 7.0 - I was getting "The procedure entry point GetProcessImageFileNamew could not be located in the dynamic link library PSAPI.dll" error message at 99% of installation progress bar. So I had to uninstall IE 7.0 to get it working. Funny thing is after you install SOA Suite, you can install IE 7.0 and it works perfectly.

  • Firewall - My McAfee firewall blocked opmn service. So the Recommended installation was failing during installation. Disable your firewall or make exclusion list during installation.

The above two problems were resolved after 4 hrs OWC session with Oracle Support.

You can continue with the later part of the article, if your environment is set up.
BPEL Process using Email Activity
Notification services in BPEL are exposed as web services. The notification service sends email using SMTP and receives email from IMAP-based or POP-based email accounts. You can use Email activity in the component palette to add email notification of BPEL process. You can directly enter the required and optional email addresses and message content (subject and body) or you can use the following built-in functions:
  • Identity lookup dialog: Browse the user directory that is configured for use by Oracle BPEL Process Manager—Oracle Internet Directory (OID), JAZN/XML, LDAP, and so on.
  • XPath Expression Builder: For recipient email addresses (To, Cc, Bcc, Reply To), you can use the XPath Expression Builder to get email addresses dynamically from the input.

For my example, I will directly enter the recipient email address, subject and body in email activity fields.

Before using email activity, you must set up configuration details for email accounts in the ns_emails.xml file, found at <SOAHOME>\bpel\system\services\config

Configuring Email Accounts in ns_emails.xml:
ns_emails.xml is found in <SOAHOME>\bpel\system\services\config folder.

1. Make a backup copy of the ns_emails.xml file.

2. Open ns_emails.xml in Text Editor and Change the NotificationMode from "NONE". NotificationMode can be set to the following:
  • EMAIL - If you have only email setup, but not other channels like voice, SMS, fax, etc.
  • ALL     - if you have email and other channels like voice, SMS, fax, etc. set up.

I will be using only email, so I have set NotificationMode to "EMAIL".
3. Configure Default EmailAccount. When Email activity is selected in BPEL process, From Account field is defaulted  with "Default". If "Default" email account is not configured in ns_emails.xml, email notification is not sent to the recipient.

Also this account is used when no account is specified to receive an email notification. This account is also used to send task-related notifications. A default email account must always be specified in the configuration file i.e ns_emails.xml

Change FromAddress, OutgoingServerSettings, IncomingServerSettings elements to your desired email address and your smtp host name as below.

4. This step is Optional. Define the parameters for the additional email account with an additional <EmailAccount> </EmailAccount> structure. For Example: If I defined 'Apps2Fusion' email account, I can use 'Apps2Fusion' in From Account field in Email activity.


5. Save ns_emails.xml

Configuring wf_config.xml:
wf_config.xml is found in <SOAHOME>\bpel\system\services\config folder. It is a workflow configuration file.

Add the below property to wf_config.xml

<property name="" value="1" />

This property specifies the interval for sending notifications. If this property is absent, the notifications are sent every 15 mins (default) or after starting the SOA Suite.

Once the cofiguration files i.e ns_emails.xml and wf_config.xml are edited, Start your SOA Suite and JDeveloper. If you have already started SOA Suite before editing these configuration files, restart the SOA Suite.

Creating Email Activity in BPEL Process

Open SOA Launch Console and Click on Application Server Control link.
Login with username/password and go to Runtime Ports link at the bottom.
Write down the RMI port number. We will use this port for creating Application Server connection in JDeveloper.
Open JDeveloper. Create Application Server Connection and test it.
RMI Port 12401 is fetched from above screenshot.

Create Integration Server connection using the above application server connection. Test it.

Now I will create Asynchronous BPEL project. My BPEL process looks like in below screenshot.

I will drag the Email Activity from Component Palette (left most frame), on to BPEL process in between the receive and response activities.

Configure the fields in Email activity. From Account is defaulted with 'Default' email account name. Default email account settings are taken from ns_emails.xml

You can also use XPath Builder to set the fields dynamically from input variables.
Click OK. I've renamed the activity to "SendEmail". Email is a complex activity like a subprocess in workflow. You can click on "+" of email activity to expand it. It contains Assign activity which assigns the values for the different parameters of email, and Invoke activity to initiate Notification Service. If NotificationMode parameter in ns_emails.xml is not changed from "NONE", the notification is sustained here.

Save All. Deploy the process on to Integration Server.

Now Login to BPEL Control and Click on the process name in the dashboard.
Click on Post XML Message to manually kick off the process.

Check the email. I've received email successfully.

But the message text came as an attachment. So I went back to my email activity and unchecked Multipart message attachments. I've deployed and ran the process again.

Bravo !!! I got the email notification as I wanted.

You can view the flow and the xml data at each activity. Click on Instances in BPEL Console, then Flow tab.

To revise the whole process to send email notifications, I'm briefing the steps below:
  1. Set your SOA Suite enviroment for development.
  2. Configure ns_emails.xml and wf_config.xml
  3. CreateAsynchronous BPEL Process
  4. Create Email acitivity and enter values for To, Subject and Body fields
  5. Save and Deploy the Process
  6. Manually initiate the process
  7. Check the email

In this article, I've manually initiated the process to send notification. I will automate this step to schedule the bpel process in the next article.


  1. thanks for sharing the information on oracle middleware. The way you described is so impressive and appreciative.and finally you provided the steps for processing email notification is very useful .keeping posting posts like this.
    Thank you.
    oracle R12 training

  2. Thanks for sharing the useful content on oracle middleware and good points were mentioned in the blog.

    Oracle Fusion

  3. CALFRE handles oracle fusion financials online training and its modules maintaining classroom based training with the self-paced videos. An expert having ten plus years of self-experience handles the training period through online and explains each and every point perfectly. We recently launched our institute in the USA and getting the best reputation over there.

    Oracle fusion Financials Online Training in Ameerpet

    Oracle Fusion Financials Training in Ameerpet