Thursday, January 14, 2010

Sending mail in BPEL

found a great site which explains the concept oe SMTP.do have a look in the same

http://www.faqs.org/rfcs/rfc821.html


First of all we need to check if the mail server is running or not.So we will first of all check through telnet whether we are able to send the mail to others or not.We will be checking whether POP3, IMAP4 and SMTP are running and accepting connections or not.

By default IMAP4 listens on port 143, POP3 on port 110 and SMTP on port 25.

If you have a different configuration you can check it by following command.

oesctl show targets

If there are no processes running, try to start them using the following command

oesctl startup


Now we will try to send a mail to someone throught telnet and check if our SMTP is working properly.

open a command window prompt and type

telnet mail.example.com 25

Here depending upon your domain you can replace your example.If some one is working at oralce he can replace it with mail.oracle.com or what ever the SMTP server name is.



One you will enter the value and say enter you will be logged in to the SMTP server
nad will get the following screen.





Now once you entered type

HELO mail.example.com

YOu will get the following output

HELO mail.example.com
250 mail.example.com Hello local.example.com, pleased to meet you

Now in the command prompt type the mail of the sender the syntax used for this is

mail from: someone@example.com

it will give you the result

Sender OK

Again define the receipient by using following syntac

rcpt to: sometwo@example.com

It will give the result Recepient OK

Now our purpose is only to check if SMTP server is running or not so we will just send a simple data and check if it works properly or not.

Just type DATA in the command prompt and say enter you will get the following input

354 Enter mail, end with "." on a line by itself

now type youe message here and say enter and in next line give a fullstop.This states to the SMTP server that the message is over you can process the mail now.

So our full screeen will look something like this



Now once done just say quit and it will disconnect from your server.Now check for the mail if you have received the mail from someone@example.com to sometwo@example.com.If you receive it it means your SMTP server is working correctly.Similary you can check for IMAP and POP3 also.

Now once you have checked that your SMTP server is working you can go ahead and configure your bpel process for email notification.Please keep in mind you may encounter some issue while testing so be sure that your domain is existing,the email address you are providing is valid,You have specified the sender and receiver correctly and in this order only sender->Receiver.

YOu can use the telnet session to connect to IMAP and POP3 but the commands are different for them.You can refer to internet for the same.A lot of links provide the use case.


I have always come across a lot of issues while configuring the email notification.I am explaining the exact steps which we need to perform in order to make it wokring.I am not talking about configuring it with human task.I am just considering here how to make a simple email activity to send email.

For the email to work properly you need to configure the following file

SOA_HOME/bpel/system/services/config/ns_emails.xml

MOst of the time issue occurs because ns_emails.xml is not configured properly.


The configuration file ns_emails.xml must contains at least two entries of type EmailAccount

1. The default acount-By default there is one account in the ns_email.xml file which is used for human -task related function. This account is used when there is no account specified to which to send an e-mail notification.A default e-mail account must always be specified in the configuration file.

2. The user email account-This needs to be specified as to mention who is the end user to receive the email.

So we need to make the following changes in our configuration file.

1>First of all Change the NotificationMode to EMAIL

So it should look like

EmailAccounts xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService"
EmailMimeCharset="" NotificationMode="EMAIL"


Now you should have two account in your configuration file.one is the default account and another one is user account.so two entry should appear like this.

The default account should be appearing like



Again your user email account should be looking like this



Please fill all the sections properly.Here you have to keep in the mind that the email address that you have defined for default account and the one for user account must be different.do specify the password.So once you haave configured the user account also your full configuration should be having entry like

email account
default account
user account
email account.

Now save the file and now go to your jdeveloper.there in click on the email activity and provide in the from name the name of the user account that you have created in ns_emails.xml and in to provide the email of the user to whom you want to send the information.It should looke like this




SAve the changes and deploy your project again.Now try to run the program and you should be able to get the email.If you are not getting an email try to change the from name "arpit.rahi@example.com" to arpit.rahi and check.

You may also craete the user account from em console.

go to

BPEL Process Manager => Administration => Notification Service Properties => E Mail
Accounts, click "Create" and enter values for a new mail account.If you have done all the setting as explined you should not get an issue with email activity in BPEL.The email notification used with human task is different and we need to configure one more configuration file in addition to ns_emails.xml.In that case you need to additionally configure user-properties.xml and wf_config.xml.We will check it later

So to summarize you have to change your ns_emails.xml file as

<EmailAccounts xmlns="http://xmlns.oracle.com/ias/pcbpel/NotificationService"

EmailMimeCharset=""

NotificationMode="EMAIL">

<EmailAccount>

<Name>Default</Name>

<GeneralSettings>

<FromName>Your Name</FromName>

<FromAddress>*Your Email: ***@***.com*</FromAddress>

</GeneralSettings>

<OutgoingServerSettings>

<SMTPHost>*mail.***.com*</SMTPHost>

<SMTPPort>25</SMTPPort>

</OutgoingServerSettings>

<IncomingServerSettings>

<Server>*mail.***.com*</Server>

<Port>993</Port>

<Protocol>IMAP</Protocol>

<UserName>***@***.com</UserName>

<Password ns0:encrypted="false" xmlns:ns0="http://xmlns.oracle.com/ias/pcbpel/NotificationService">***</Password>

<UseSSL>true</UseSSL>

<Folder>Inbox</Folder>

<PollingFrequency>1</PollingFrequency>

<PostReadOperation>

<MarkAsRead/>

</PostReadOperation>

</IncomingServerSettings>

</EmailAccount>

</EmailAccounts>


If you want BPEL to send email notification at a regular interval of 1 minute

Add the following property to wf_config.xml (in SOA_HOME\bpel\system\services\config directory):



Restart you SOA suite.

1 comment:

Anonymous said...

Hey Arpit , This explanation is wonderful.