Custom eMail Task integration

Hi,

we are currently integrating Flowable into our existing infrastructure, but there is one point I cannot figure out:

We need to use our custom eMail sending framework for sending outgoing mail (using the Mail Task) and cannot use the built-in mail sending code. Is there any way to configure the whole Process Engine to use our mail sending code? I read something about MailActivityBehaviour but I could not figure out how to configure some custom logic here…

Thanks in advance,
Mike

Hi Mike,
have you tried to extend the DefaultActivityBehaviorFactory and overwrite the method protected MailActivityBehavior createMailActivityBehavior(String taskId, List<FieldExtension> fields)? There you should be able to instantiate your own implementation of the MailActivityBehavior? Afterward, you should be able to set the ActivityBehaviorFactory during the creation of your ProcessEngineConfiguration, see therefore https://www.flowable.org/docs/userguide/index.html#_creating_a_process_engine

Kind regards,
Valentin

Hey Mike,

What Valentin suggested will help you create your own implementation.

I on the other side are interested to know why using the current implementation is not sufficient. Is there something that is missing? We can of course extend and add more functionality to the Mail Task so you can use it as is. Is it possible for you to share this information?

Cheers,
Filip

Hi,

I tried Valentins solution and it was exactly what I needed, thank you!

Filip, I dont think anything is missing from the Mail task but we have a setup where we have to use a database based mail queue for documentation reasons. Also some messages are not sent using email but using messaging services - this is transparent to the business process logic.

Regards,
Mike

Sory for refreshing topic.
@mtraunau have you implemented your own ActivityBehaviourFactory? Can you share how it is done?

@valentin Is there any example how to override ActivityBehaviourFactory? I tried to setActivityBehaviour in ProcessEngineConfiguration but it makes whole configuration manual which I want to avoid (database, transaction etc.) or I do something wrong.

Hi @dcwik96,

in case you are using Spring, have you tried to use a EngineConfigurationConfigurer?

Valentin

1 Like

Hi,

in fact i did implement an ActivityBehaviourFactory. It looks like this:

public class DataReporterActivityBehaviorFactory extends DefaultActivityBehaviorFactory {


  @Override
  public MailActivityBehavior createMailActivityBehavior(ServiceTask serviceTask) {
    return createMailActivityBehavior(serviceTask.getId(), serviceTask.getFieldExtensions());
  }

  @Override
  public MailActivityBehavior createMailActivityBehavior(SendTask sendTask) {
    return createMailActivityBehavior(sendTask.getId(), sendTask.getFieldExtensions());
  }

  protected MailActivityBehavior createMailActivityBehavior(String taskId, List<FieldExtension> fields) {
    List<FieldDeclaration> fieldDeclarations = createFieldDeclarations(fields);
    return (MailActivityBehavior) ClassDelegate.defaultInstantiateDelegate(DataReporterMailActivityBehavior.class, fieldDeclarations);
  }

}

The ActivityBehaviour itself looks like this:

public class DataReporterMailActivityBehavior extends MailActivityBehavior {

  @Override
  public void execute(DelegateExecution execution) {

		...

    leave(execution);
  }

}

Configuration for the whole engine is done here:

try {
	// Create Flowable engine
	ProcessEngineConfiguration pec = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
	pec.setDataSource(ds);

	pec.setAsyncExecutorActivate(true);

	ArrayList<FlowableEventListener> eventListeners = new ArrayList<FlowableEventListener>();
	eventListeners.add(new DefaultEventLogging());
	pec.setEventListeners(eventListeners);

	((ProcessEngineConfigurationImpl) pec).addConfigurator(new FormEngineConfigurator());
	((ProcessEngineConfigurationImpl) pec).setActivityBehaviorFactory(new DataReporterActivityBehaviorFactory());


	pec.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

	pec.buildProcessEngine();
	log.info("Flowable Business Process engine startup ready");

} catch (Exception e) {
	log.log(Level.SEVERE, "Flowable Initialization error", e);
	return false;
}

I hope this helps - I wrote this code some months ago so I can’t recall the exact details…

Best regards
Michael

1 Like