Always send an email when a task is created

I have found example of attaching task listener so that an email is sent when the task is created.

Is it possible to have this behaviour for all processes, without attaching the delegate specifically to a task? Also, there will be some user tasks that can be created on the tasklist, is there a way to do that?

Hi @Edmondo_Porcu
Have a look at below link

Thanks Hassang,

that’s what I was looking for. I think it’s misleading that it is under cdi-java-ee as we are not using any java-ee at all.

How do I retrieve then the emails of all the potential assignee for that tasks?

Thank you


You could also take a look at using Process Application Event Listener, in that case you’d have direct access to the task object.

Hi @Edmondo_Porcu

The observer method has the parameter
BusinessProcessEvent businessProcessEvent
You could get the delegate task through
businessProcessEvent.getTask() from where you could get the assignee by calling getAssignee()

You could get the email from user profile as in below example

Hi @Edmondo_Porcu,

you can also use the extension Camunda BPM Reactor and register a listener for task events.

Best regards,

1 Like

Hi … the reactor extension would be my tool of choice here as well, but I as the author, am biased … what you can do, if you want to simulate the behavior:

  • add a custom BpmnParseListener (either directly to the configuration or via ProcessEnginePlugin#preInit()
  • in that parse listener, register your “send eMail notification” code as a taskListener for task#create:
BpmnParseListener emailParseListener = new AbstractBpmnParseListener(){
    public void parseUserTask(Element userTaskElement, ScopeImpl scope, ActivityImpl activity) {
            TaskDefinition taskDefinition = ((UserTaskActivityBehavior) activity.getActivityBehavior())
            taskDefinition.addTaskListener(TaskListener.CREATE, new TaskListener(){
                     public void notify(DelegateTask delegateTask) {
                               // your email code here

1 Like

I have implemented your advice but the getTaskHandler on my ServletApplication never gets invoked. Do I need to add something else?

I would need some code/more info, please.

class ScalatraBootstrap extends AbstractProcessApplication with LifeCycle {

val taskListener = buildTaskListener

override def init(context: ServletContext) {
val defaultProcessEngine = RuntimeContainerDelegate.INSTANCE.get().getProcessEngineService.getDefaultProcessEngine

override def getTaskListener: TaskListener = taskListener

override val autodetectProcessApplicationName: String = “credimi-workflows”

override def getReference: ProcessApplicationReference = {
atomicReference.compareAndSet(null, new ProcessApplicationReferenceImpl(this))

override def destroy(context: ServletContext): Unit = {“Undeploying app”)

This is our simple Servlet, which we deploy as a war on a tomcat where we installed a shared process engine. The getTaskListener method is never invoked