This example demonstrate how to
- use the
MailNotificationService
to get informed while receive a new mail, - send a mail with an attached file
- Build the WAR using Maven
mvn install
- Download a Camunda Distribution
- Copy the WAR
camunda-bpm-mail.example.print-service-${VERSION}.war
into the webapps / deployments folder - Copy the JAR
camunda-bpm-mail-core-${VERSION}.jar
into the application server lib folder (and make sure that the required dependencies are available - like JavaMail 1.5.5) (e.g. tomcat folder:server\apache-tomcat-8.0.24\lib
) - Copy the mail configuration
src/main/resources/mail-configuration.properties
to application server config folder and adjust it (e.g. tomcat folder:server\apache-tomcat-8.0.24\conf
) - Set the environment variable
MAIL_CONFIG
to the path where you copied the mail configuration - Start the application server
- Send a mail with the attached file which should be printed
- Check that a user task is created - complete it
- Now, check your mails
Also try to send a mail without attachment.
You can also use the ProcessIntegrationTest to run the example as a JUnit test with an embedded process engine.
Create an instance of the MailNotificationService
, register the handler and start the service. When a new print order is received via mail, the service invokes the handler which starts the process and pass the received mail into it as process variable.
configuration = MailConfigurationFactory.getConfiguration();
notificationService = new MailNotificationService(configuration);
notificationService.registerMailHandler(mail -> {
runtimeService.startProcessInstanceByKey("printProcess",
Variables.createVariables()
.putValue("mail", mail)
.putValue("invoice", getInvoicePath()));
});
notificationService.start();
When the order is processed (i.e. complete user task 'print it') then the process sends a mail with the attached invoice (invoice.pdf
) using the mail-send
connector. The path of the invoice is stored in the process variable invoice
.
<bpmn:serviceTask id="ServiceTask_1ry54cw" name="send invoice">
<bpmn:extensionElements>
<camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="to">${mail.getFrom()}</camunda:inputParameter>
<camunda:inputParameter name="subject">invoice</camunda:inputParameter>
<camunda:inputParameter name="fileNames">
<camunda:list>
<camunda:value>${invoice}</camunda:value>
</camunda:list>
</camunda:inputParameter>
</camunda:inputOutput>
<camunda:connectorId>mail-send</camunda:connectorId>
</camunda:connector>
</bpmn:extensionElements>
<!-- ... -->
</bpmn:serviceTask>