Send email and in-app notifications
Send a template email with action/mail. The complete task-reminder example includes the mail view, native module definition, workflow and tests.
Complete example: acme_deadline_reminder
Purpose (translated from upstream README)
Adapt (translated from upstream README)
Files relative to the system root:
├── README.md├── fixtures/│ └── native.module.bake.json├── menu.bake.json├── modules/│ └── acme_tasks/│ ├── acme_tasks.detail.json│ ├── acme_tasks.index.json│ └── acme_tasks.module.bake.json├── preview/│ └── sample.bake.json├── tests/│ ├── acme_deadline_due.test.workflow.json│ └── acme_deadline_empty.test.workflow.json├── translations/│ ├── de.json│ ├── en.json│ └── translations.bake.json├── views/│ ├── deadline.twig│ └── deadline.view.bake.json└── workflows/ └── acme_remind_deadlines.workflow.bake.jsonREADME.md
# acme_deadline_reminder
Aufgaben / Tasks. Tägliche Erinnerung für heute oder morgen fällige Aufgaben. Cron ist in events[] registriert; jeder Treffer erhält eine E-Mail aus einer Twig-View und danach reminded=true. Das Merk-Feld verhindert normalen Doppelversand; parallele Läufe oder ein Absturz zwischen Versand und Speichern sind nicht atomar.
## Dateien
- `modules/`: Schema sowie Detail- und Index-Layouts.- `menu.bake.json`: Navigation (in ein vorhandenes Menü übernehmen).- `translations/`: deutsche/englische Labels und Bakery-Ressource.- `workflows/`, `tests/`: ausführbare Graphen und isolierte Business-Tests mit Fixtures.- `preview/`: optionale Bakery-Beispieldaten; nur in einer Vorschau anwenden.
## Anpassen
Alle `acme_*`-Modul-, Workflow-, Event- und Ressourcen-Identifier gemeinsam umbenennen; Referenzen, Layoutpfade, Filter, Übersetzungsschlüssel und Tests mitändern. Weitere Felder in Schema, Layout und beiden Sprachen ergänzen. Dateien relativ zur Systemwurzel kopieren. Native Module aus `fixtures/` nur ergänzen, wenn sie fehlen; bestehende Definitionen zusammenführen. Menüeinträge und Vorschaudaten sind optional. Varianten separat prüfen, nicht zusätzlich zur Hauptdefinition anwenden.
Prüfen: `php bakery plan <system>`, `php bakery apply <system>`, dann `php bakery system test-run <system>`. In diesem Repository führt `AcmeFeatureExamplesTest` dieselben Plan-/Apply-Schritte und die Workflow-Tests in der wegwerfbaren PHPUnit-Systemdatenbank aus. UI-Darstellung und reine Client-Aktionen sind damit nicht geprüft.
`views/` enthält die Mailvorlage und `resource_view`; `fixtures/` das native Views-Modul. Empfängerfeld, Datumsfenster und Uhrzeit gemeinsam in Workflow und Tests anpassen. Der Test friert `now` ein und ruft den Cron-Einstieg direkt auf; er prüft nicht die Scheduler-Uhr. SMTP muss im Zielsystem eingerichtet sein; Tests versenden nicht. Das feste Vorschaudatum bei Bedarf ändern.fixtures/native.module.bake.json
[ { "resource_module": "views", "import": true, "resource": { "identifier": "views", "type": "views", "title": "name", "fields": [ { "identifier": "name", "type": "text" }, { "identifier": "type", "type": "text" }, { "identifier": "code", "type": "code" } ] } }]menu.bake.json
[ { "resource_menu": "acme_deadline_reminder", "resource": { "name": "ACME Inc.", "elements": [ "acme_tasks" ] } }]modules/acme_tasks/acme_tasks.detail.json
{ "tabs": [ { "identifier": "general", "rows": [ { "cols": [ { "span": 24, "components": [ { "type": "field_group", "identifier": "general", "options": { "fields": [ "name", "due_at", "email", "reminded" ] } } ] } ] } ] } ]}modules/acme_tasks/acme_tasks.index.json
{ "tabs": [ { "identifier": "general", "rows": [ { "cols": [ { "span": 24, "components": [ { "type": "resource_table", "identifier": "records", "options": { "module": "acme_tasks" } } ] } ] } ] } ]}modules/acme_tasks/acme_tasks.module.bake.json
[ { "resource_module": "acme_tasks", "resource": { "identifier": "acme_tasks", "title": "name", "fields": [ { "identifier": "name", "type": "text" }, { "identifier": "due_at", "type": "date" }, { "identifier": "email", "type": "email" }, { "identifier": "reminded", "type": "checkbox", "options": { "default": false } } ], "layouts": { "detail": "/modules/acme_tasks/acme_tasks.detail", "index": "/modules/acme_tasks/acme_tasks.index" } } }]preview/sample.bake.json
[ { "resource_entity": "acme_sample_task", "resource": { "module": "acme_tasks", "fields": { "name": "ACME Inc. deadline", "due_at": "2026-12-25", "email": "reminder@example.invalid", "reminded": false } } }]tests/acme_deadline_due.test.workflow.json
{ "identifier": "acme_deadline_due", "workflow": "acme_remind_deadlines", "fixtures": [ { "type": "entity", "module": "acme_tasks", "alias": "due", "fields": { "name": "ACME Deadline", "due_at": "2026-12-25", "email": "due@example.invalid", "reminded": false } }, { "type": "entity", "module": "acme_tasks", "alias": "later", "fields": { "name": "Later", "due_at": "2026-12-28", "email": "later@example.invalid", "reminded": false } }, { "type": "entity", "module": "acme_tasks", "alias": "already", "fields": { "name": "Already reminded", "due_at": "2026-12-25", "email": "already@example.invalid", "reminded": true } }, { "type": "entity", "module": "acme_tasks", "alias": "past", "fields": { "name": "Past", "due_at": "2026-12-20", "email": "past@example.invalid", "reminded": false } } ], "trigger": { "type": "dispatch_sync", "entry": "acme_deadline_daily" }, "assertions": [ { "type": "mail_sent", "to": "due@example.invalid", "subject": "ACME Inc. — Deadline reminder", "body_contains": "ACME Deadline", "count": 1 }, { "type": "mail_not_sent", "to": "later@example.invalid" }, { "type": "mail_not_sent", "to": "already@example.invalid" }, { "type": "mail_not_sent", "to": "past@example.invalid" }, { "type": "field_equals", "field": "reminded", "value": true, "module": "acme_tasks", "selector": { "id": "fixture:due.id" } }, { "type": "field_equals", "field": "reminded", "value": false, "module": "acme_tasks", "selector": { "id": "fixture:later.id" } } ], "now": "2026-12-24 09:00:00", "steps": [ { "type": "dispatch_sync", "entry": "acme_deadline_daily", "assertions": [ { "type": "mail_sent", "to": "due@example.invalid", "count": 1 } ] } ]}tests/acme_deadline_empty.test.workflow.json
{ "identifier": "acme_deadline_empty", "workflow": "acme_remind_deadlines", "fixtures": [], "trigger": { "type": "dispatch_sync", "entry": "acme_deadline_daily" }, "assertions": [ { "type": "mail_not_sent", "subject": "ACME Inc. — Deadline reminder" } ], "now": "2026-12-24 09:00:00"}translations/de.json
{ "modules": { "acme_tasks": { "title": "Aufgaben", "fields": { "name": "Name", "due_at": "Fällig am", "email": "E-Mail", "reminded": "Erinnert" }, "tabs": { "general": "Allgemein" } } }}translations/en.json
{ "modules": { "acme_tasks": { "title": "Tasks", "fields": { "name": "Name", "due_at": "Due date", "email": "Email", "reminded": "Reminded" }, "tabs": { "general": "General" } } }}translations/translations.bake.json
[ { "resource_translations": "de", "resource": { "identifier": "de", "code": "de_DE", "name": "Deutsch", "dir": "ltr", "provider": "deDE", "data": "${file('translations/de.json')}" } }, { "resource_translations": "en", "resource": { "identifier": "en", "code": "en_US", "name": "English", "dir": "ltr", "provider": "enUS", "data": "${file('translations/en.json')}" } }]views/deadline.twig
<html><body><h1>ACME Inc.</h1><p>{{ task.name }}: {{ task.due_at }}</p><p>Reminder / Erinnerung</p></body></html>views/deadline.view.bake.json
[ { "resource_view": "acme_deadline_mail", "depends_on": "resource_module.views", "resource": { "module": "views", "fields": { "name": "acme_deadline_mail", "type": "twig", "code": "${file('views/deadline.twig')}" } } }]workflows/acme_remind_deadlines.workflow.bake.json
[ { "resource_workflow": "acme_remind_deadlines", "resource": { "identifier": "acme_remind_deadlines", "title": "ACME Inc. — acme_remind_deadlines", "active": true, "async": false, "entry": "acme_deadline_daily", "elements": [ { "name": "acme_deadline_daily", "type": "event/cron", "options": { "frequency": [ [ { "schedule": "dailyAt", "parameters": [ "08:00" ] } ] ], "client": null }, "to": { "default": { "dueTasks": [ "default" ] } } }, { "name": "dueTasks", "type": "source/entities", "options": { "module": "acme_tasks", "filters": [ [ { "left": { "type": "field", "value": "due_at" }, "operator": ">=", "right": { "type": "recipe", "value": "date().format(\"Y-m-d\")" } }, { "left": { "type": "field", "value": "due_at" }, "operator": "<=", "right": { "type": "recipe", "value": "date().addDays(1).format(\"Y-m-d\")" } }, { "left": { "type": "field", "value": "reminded" }, "operator": "=", "right": { "type": "any", "value": false } } ] ] }, "to": { "default": { "eachTask": [ "default" ] } } }, { "name": "eachTask", "type": "flow/each", "options": {}, "set": { "task": "each:" }, "to": { "each": { "sendReminder": [ "default" ] } } }, { "name": "sendReminder", "type": "action/mail", "options": { "to": { ".recipe": "$task.email" }, "subject": "ACME Inc. — Deadline reminder", "view": "acme_deadline_mail", "view_data": { "task": "$task" }, "from": "reminders@example.invalid" }, "in": { "default": "$task" }, "to": { "mailSuccessful": { "markReminded": [ "default" ] } } }, { "name": "markReminded", "type": "op/set", "options": { "recipes": { "reminded": "true" } }, "in": { "default": "$task" }, "to": { "default": { "save": [ "default" ] } } }, { "name": "save", "type": "action/save", "options": { "triggerEvents": false }, "to": {} } ], "events": [ { "identifier": "acme_deadline_daily", "type": "cron", "frequency": [ [ { "schedule": "dailyAt", "parameters": [ "08:00" ] } ] ] } ] } }]Source: brezel/api@572da72238ad1aab7b60287c898eaede2c08a876
Agents: system_authoring_command reference kind=feature query=acme_deadline_reminder
How it works
Section titled “How it works”action/mail chooses a named resource_view. view_data maps template variables to recipes, and the Twig view supplies subject/body content. The to recipe reads the task email. Configure a real sender and SMTP in the target system. The reminder marker is saved only on mailSuccessful.
Test it
Section titled “Test it”Copy the example files relative to your system root. Merge existing native modules, menus and roles; rename all related identifiers together. Apply preview data only in a disposable preview. Run the plan, apply and tests against that preview:
php bakery plan <system>php bakery apply <system>php bakery system test-run <system>Run acme_deadline_due and acme_deadline_empty; mail_sent checks fake delivery, recipient and body. No real email is sent. Add cases for changed recipients, template variables and the failure branch before adapting the workflow to another business event.
Other ways
Section titled “Other ways”- Recommended for in-app or web-push messages:
action/notifywith thenotificationgroup. - Recommended for bundling channels in one element:
action/notifywithmail,notification,toastorsmsgroups. For a dedicated email useaction/mail. - Not recommended for template email: hard-coding rendered business content in several workflows; keep the template in a view.
Reference
Section titled “Reference”Mail options · Notifications · Views · Workflow tests · Assertions