Bonita is an open-source platform for automating business processes. Bonita Studio (IDE) contains all the elements needed to develop the processes. It is a graphical environment for creating processes, applications, data models, and user’s views (pages and forms). The Bonita IDE is built on top of the well-known development environment eclipse.

This blog explains how a Bonita case can be created upon receiving a new email in the inbox. This has two different processes: one is continuously listening to the email inbox (email listener process) and another (callee process) is the actual process for which a new case is created. Email listener process has only one active case (never ending) which will be listening to the email inbox on a continuous interval (which can be supplied through the process parameter). The callee process details will also be supplied through the respective process parameters so that the listener process knows about the callee process for process instantiation.

Real-time Usage

Email to case can be used in certain issues we encounter in resolving day-to-day problems. Few of them are explained below:

  • Order placements
  • Raising complaints
  • Feedback provision

Complaints are raised where it is inevitable to raise a process request whenever a new complaint from the customers is received. The complaints can certainly be through an email and whenever a new email arrives to the inbox, the complaint/process request should be created accordingly. This can be fully automated trough the Bonita email to case request. Feedback is another place where after the completion of any event the performer would look for the feedback for the quality purpose. This can be done when a new email is received for feedback and later a case can be initiated accordingly.

Bonitasoft BPM Services from Evoke Technologies

Glance of the Processes Used

Email Listener Process

The process looks as shown below. It has two major tasks (scripts): Poll Email and Instantiate Callee Process. We’ll deep dive into these steps in the coming sections.

Poll Email

Poll email step is responsible for poking the email server at a specified interval for the arrival of new emails. If it encounters any new email, then the information is being stored in the process variable and the same can be used for the process instantiation. Once if the mail is read, then it will be marked as seen so that the case creation for the same email can be stopped in the successive turns.

The code snippet from the fetchAllEmails is shown below.

public List<String> readMails() {

Logger logger = Logger.getLogger(“org.bonitasoft.checkEmailStatus”);“Inside fetchAllEmails method”);

List<String> mailsList = new ArrayList<>();

Session session = null;

Store store = null;

Folder inbox = null;

String userName = “”;// provide user name

String password = “XXXXXXXX”;// provide password

Properties properties = new Properties();

properties.setProperty(“”, “”);

properties.setProperty(“mail.port”, “995”);

properties.setProperty(“mail.transport.protocol”, “imaps”);“Inside fetchAllEmails method…”);

session = Session.getInstance(properties, new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(userName, password);



try {

store = session.getStore(“imaps”);


inbox = store.getFolder(“INBOX”);;

Message[] allMessages = FlagTerm(new Flags(Flag.SEEN), false));“Number of mails = ” + allMessages.toString());

if(allMessages.length > 0){

for (int i = 0; i < allMessages.length; i++) {

Message message = allMessages[i];


Address[] from = message.getFrom();“——————————-“);“Date : ” + message.getSentDate());“From : ” + from[0]);“Subject: ” + message.getSubject());“Content :”);







} catch (NoSuchProviderException e) {“——————————–“+e.getMessage());

} catch (MessagingException e) {“——————————–“+e.getMessage());


return mailsList;


List of parameters for the process are as shown below. It has three parameters which are used for instantiation of the other process.

Instantiate Callee Process

Instantiate callee process is responsible for creation of the case. It holds a connector, which will be invoked in certain intervals as specified by the process parameter. If this connector finds any new emails from Poll Email task, it instantiates the callee process. The code under this task may look like this:

Logger logger = Logger.getLogger(“org.bonitasoft.instantiateCalleeProcess”);“Inside instantiateCalleeProcess “);

ProcessAPI processAPI = apiAccessor.getProcessAPI();

long procDefId = processAPI.getProcessDefinitionId(processToCall, processVersion);“procDefId is: “+procDefId);

ProcessDefinition procDef = processAPI.getProcessDefinition(procDefId);“procDef is: “+procDef);

User user = apiAccessor.getIdentityAPI().getUserByUserName(“lsp_user1”);“user is: “+user.getId());

for(String localMessage : mailsList){“################ Creating case with: “+localMessage);

JSONObject contractMap = new JSONObject();

contractMap.put(“header”, localMessage);

ProcessInstance processInstance = processAPI.startProcessWithInputs(user.getId(),

procDef.getId(), contractMap);“Case was created with header: “+ localMessage + ” and case id: ” +



Callee Process

The callee process is a new process for which the new process instances will be created based on the new email arrivals. This process information will be supplied to the main (Poll Email) process through the process parameters as mentioned above.

End form from the mails data will look as shown below.


Email to case in Bonita can be useful in many ways to automate major processes without human intervention. By following the steps advised above Bonita case instantiation upon new email arrival can be achieved.

Wish to know more about Bonita Case Creation? Feel free to leave your question below. We’ll get back to you in the shortest possible time.