This example demonstrates how to send emails from JavaDelegates using Spring Mail, and how to verify email delivery in integration tests using Mailpit as an SMTP server via Testcontainers.
- How to inject
JavaMailSenderinto aJavaDelegateand composeSimpleMailMessageobjects - How to configure
spring-boot-starter-mailinapplication.yaml - How to run Mailpit as a Testcontainers
GenericContainerfor SMTP and API access - How to verify sent emails by querying the Mailpit REST API from integration tests
- How to model a job-application process with confirmation and decision emails
- JDK 21
- Docker (tested with Docker Desktop 4.x and Rancher Desktop 1.x)
Start the infrastructure:
docker compose up -dRun the application:
# Make wrappers executable on macOS/Linux
chmod +x mvnw gradlew
./mvnw spring-boot:run
# or
./gradlew bootRunAccess the Operaton web apps at http://localhost:8080 with credentials demo / demo.
The Mailpit web UI is available at http://localhost:8025 — view all sent emails here.
Submit an application:
curl -s -X POST http://localhost:8080/engine-rest/process-definition/key/job-application/start \
-H "Content-Type: application/json" \
-d '{
"variables": {
"applicantName": {"value": "Jane Doe", "type": "String"},
"applicantEmail": {"value": "jane@example.com", "type": "String"}
}
}'Open http://localhost:8025 — you should see a confirmation email for Jane Doe.
Approve the application via Tasklist:
- Open http://localhost:8080/operaton/app/tasklist (demo/demo)
- Claim the "Review application" task
- Complete it with variable
approved = true
A second email (approval) will appear in Mailpit.
Reject path:
Complete the review task with approved = false to trigger the rejection email ("Application Update").
SendConfirmationEmailDelegate(src/main/java/.../delegate/SendConfirmationEmailDelegate.java) — sends a receipt acknowledgement to the applicant as soon as the process starts.SendDecisionEmailDelegate(src/main/java/.../delegate/SendDecisionEmailDelegate.java) — sends either an approval or rejection email based on theapprovedprocess variable.job-application.bpmn(src/main/resources/job-application.bpmn) — models the full workflow: confirmation service task → user task (HR review) → exclusive gateway → decision service task.- Mailpit is a lightweight SMTP server with a REST API for inspecting received messages. It accepts any email without relay configuration, making it ideal for local development and testing.
./mvnw verify
# or
./gradlew buildJobApplicationProcessIT starts a PostgreSQL container and a Mailpit container via Testcontainers. It proves that:
- Submitting an application sends a confirmation email to the applicant
- Completing the review task with
approved = truesends an approval email - Completing the review task with
approved = falsesends a rejection email
