Sending Dynamic HTML-based Emails for SOA and BPM Projects
Blog: BPM Blog Avio Consulting
Sending email notifications in Oracle BPEL or BPM projects can turn into a major effort if you are not using ADF–and sometimes even if you are using ADF. If you use ADF, you can leverage features such as HTML editors and actionable emails. But in many situations you may need a stand-alone email formatting solution that doesn’t involve ADF, that can produce a simple HTML-based email, and that doesn’t need to be actionable. You will find that that simple SOA-based approach helps you implement your requirements efficiently and effectively.
- Integrates with BPM and BPEL
- Is HTML-based and can contain dynamic information from a database
- Leverages BPEL and BPM direct assignments and role-based assignments
- Includes a template selector, for sending different types of emails
- Handles attachments
- Intercepts and redirects emails for testing purposes
A detailed description of this email notification system is described below. Upon request we would be happy to provide the actual project code describe here.
This is a sample of the input XML. Notice the data includes
- A record ID – Used to pull data from the database for embedding information in the email
- An array of “TO” email addresses – Use to lookup email addresses from user names or BPM application roles.
The Email Notification Composite
The email notification service contains a composite, as shown. This composite contains
- Send Email (BPEL) Pre-Processor – For getting email content and addressing information, prior to formatting
- Email Type Mediator – To select a style-sheet for formatting the email
- Email Service Wrapper (BPEL) – To post-process the formatted emails, as required for testing and trouble-shooting
The Email Notification Composite also contains a Get Related Email Content DB adapter and the notification service. The DB adapter is used to pull information needed for the email into an XML documents, whereas the NotificationService is the SOA suite email notification service interface. It is configured through Enterprise Manager as described in Oracle FMW Administrators Guide.
Send Email Pre-Processor
The Send Email Pre-processor pulls information from the database and translates user names and BPM application roles into email addresses. The database adapter will get application data into XML that can be extracted into an email using XSLT. Email addresses are pulled from the security provider managed by Weblogic. The user security data and email addresses can be stored in any LDAP or Active Directory security provider service.
Getting email addresses for user assignments and BPM application roles requires two nested for-loops, shown in the detailed view of Send Email BPEL process. The first one loops through user names or roles provided in the input XML,and the other loops through users in the application roles. The two key statements required are getUsersInAppRole and getUserProperty. getUsersInAppRole returns an array of users in the app role, whereas the getUsersProperty gets the email address for a given user name. The full statement is listed below. Notice that the user names contained in the application roles are iterated using the index variable $nextUserInRole whereas the list of address in the input XML is iterated using $toAddressIdx.
$nextUid = ids:getUsersInAppRole(InputVariable.request/ns2:emailHeaderData/ns2:toList/ns2:sendTo[$toAddressIdx]/ns2:userId,’OracleBPMProcessRolesApp’,false())[$nextUserInRole]
Formatting the Email
Many different types of emails can be formatted using a mediator. The mediator uses a filter to determine which XSLT is used to format the email. The selection is based on the emailType or, in this example, “HELLO_WORLD_EMAIL”.
The XSLT used for emailType = “HELLO_WORLD_EMAIL” is Format_HelloWorldEmail.xsl. This XSLT will embed data from the database and format the email as show in this example. After the XSLT formats the email, the formatted content goes into the email service wrapper described next.
Email Service Wrapper
The email service wrapper is a BPEL process that optionally re-directs the email to tester email addresses and interfaces with the SOA suite email service.
To transfer the HTML-based email into the SOA-Suite email service, you need to get the HTML element attributed from the formatting provided and embed it as a string. This is the code that performs that operation:
This is the crux of the code needed to implement your own HTML-based email service for your BPEL and BPM projects. If you have any questions, please let us know. We can provide you with a completed example. Just fill out the pop-up form so we can get back to you.