Saturday, 14 January 2012

Email Notification

Sending email notification in Oracle SOA Suite 11g using gmail

 In this post, we are going to see how to send emails in Oracle SOA Suite 11g. Instead of using a local email server, we are going to use Gmail for this purpose. If you do not have a Gmail account, now is the time to create one as you are going to need it very soon.

  I am using Oracle SOA suite you are using a slightly older version, don't worry because the steps are going to be same.So let us get started straight away.Start the weblogic server and the SOA server.Next login to the Enterprise Manger Console.For me, it is available at:


Next, expand the "User Messaging Service" node in the left pane.Next right click on the "usermessagindriver-emai(soa_server1)" node and select the "Email Driver Properties" option from the context menu.

The email driver properties page should open up.We will be setting the following values in this page:-

  • OutgoingMailServer
  • OutGoingMailServerPort
  • OutGoingMailServerSecurity
  • OutGoingUsername
  • OutGoingPassword
We are going to use Gmail for sending mails.So, enter "" as the value for "OutgoingMailServer".

Enter the value "465" for the "OutGoingMailServerPort" property.

Select the "SSL" option from the drop down for the property "OutGoingMailServerSecurity".

Enter the account username for the property "OutGoingUserName".

For the property "OutGoingPassword", select the "Use Cleartext Password" option from the "Type of Password" drop down and enter the password for the account.

Hit the "Apply" button on the top right corner of the page to apply the changes.A message will be displayed at the top of the page saying that the values has been updated successfully.

If you want to use any other popular mail provider, you can get the details from the following link:-

In this case, enter the values according to the vendor you choose.Next, restart the SOA server.

Our next step is to obtain and install the security certificates for Gmail into our JRE.For this, we are going to use "OpenSSL" to obtain the certificate.You can download "OpenSSL" from the following link:-


Download and install "OpenSSL".The path I installed it in is "C:\openssl".From now on, this is referred to as OPENSSL_HOME. To launch "OpenSSL", go to OPENSSL_HOME\bin.Then double click on the file "openssl.exe" to launch it.A new command prompt will open with "OpenSSL" prompt.

 Make sure you are connected to the internet.Next, type in the following command hit enter in the "OpenSSL" console:-

              s_client -connect

 The certificate will be output on the console itself. Copy the portion from the "BEGIN CERTIFICATE" to the "END CERTIFICATE' as indicated in the image below:-

 Open your favourite text editor, paste the copied string and save the file with the name "gmail.cert". You can use whatever name you want.Just make sure the extension of the file is ".cert".

  Next, back in the "OpenSSL" console, hit "CTRL+C". Then type in the following command and hit return:-

                 s_client -connect

Like before, copy the portion from the "BEGIN CERTIFICATE" to the "END CERTIFICATE".This time save it in a file named "gmail_imap.cert".

In the previous step, we got hold of the certificates.Next, we are going to install these certificate into our JRE.Open a new command prompt.Next, issue the following command and hit return.

keytool -import -alias smtpgmail -keystore my-trusted-certificates.jks -file C:\gmail.cert

Adjust the command according to the file location of the "gmail.cert". You will be prompted for setting up a password for the first time.Enter "changeit".The certificate will be added.

Similarly, issue the following command to add the "gmail_imap.cert" file to the key store.

keytool -import -alias imapgmail -keystore my-trusted-certificates.jks -file C:\gmail_imap.cert

After executing the commands, a new ".jks" file named "my-trusted-certificates.jks" will be create in the directory where you executed the commands from.

Now, go to SOA_HOME/user_projects/domains/domain1/bin(e.g. D:\Oracle\Middleware\user_projects\domains\domain1\bin).

Next ,edit the setDomainEnv.cmd file and replace the existing property setting with :-\Oracle\Middleware\jdk160_18\jre\bin\my-trusted-certificates.jks 


Adjust the location of the ".jks" file and the password according to your system.Restart the server once again.We are all set to go now.

Open JDeveloper if it is not already open.Next go to File->New.

In the "New Gallery", select the "Applications" node under the "General" node.In the right pane, select the "SOA Application" option and hit OK.

In the "Create SOA Application" window, enter a name for the application.To follow along, enter "GmailNotificationApp".Hit next once you are done.

In the next screen, enter a project name.To follow along, enter "GmailNotificationProject".Hit next once you are done.

In the next screen, select the "Composite With BPEL Process" option and hit finish.

Your project will be created.Next, the "Create BPEL Process" window will pop up.Enter a name for the BPEL process.To follow along, name "GmailNotifierProcess".Select the "One Way BPEL Process" template.Make sure you check the "Expose as a SOAP service" option.Hit OK once you are done.You can use the following image as a guide.

Your composite will look like the following image.

Double click on the BPEL process to open it.Next, drag and drop an email activity from the component palette and put it just below the receive activity.

Next, double click on the "email" activity.Under the "General" tab, enter the values.First, click on the expression builder button just beside "To" to bring up the expression builder.

In the expression builder, select the "input" variable under the "inputVariable" node and click on the "Insert Into Expression" button as indicated in the image below.Hit OK once you are done.

Back in the "Email" activity configuration screen, enter a value for the "Subject" and "Body".You can use expressions for these values also.Hit OK once you are done.Click on "Save All" to save the changes.

Our application is complete.You can deploy and test the application.Make sure you are connected to the internet.In the Enterprise Manager console, enter the email address where you want to send the email as the input and test the service.

No comments:

Post a Comment