BoilerPrompt
Claude Code

Claude Code prompt to add email notifications

Double-sent emails and lost sends both come from the same mistake: sending directly from request handlers. This prompt gives Claude Code an outbox pattern to implement end to end, and because it can trigger an event and read the rendered email off disk in the same session, you see actual output before anything touches a real inbox.

Last updated

Prompt
Add transactional email notifications to this app for {{resource}} events. Architecture: an outbox table in {{database}} written in the same transaction as the triggering change, a worker that polls the outbox and sends through the provider SDK, and a sent_at plus attempt count on each row so retries are bounded and idempotent. Templates live in emails/ as plain files with a subject line and text plus HTML parts; no template strings inline in application code. In development, route everything to a local capture that writes the rendered emails to disk instead of sending. Failure handling: provider errors requeue with backoff, permanently failing rows land in a dead-letter state I can query. Write tests that assert exactly one email per event even when the worker runs twice. Run the tests, then trigger one event locally and show me the rendered file on disk.

Customize it

Runs in your browser. Nothing you type here is sent anywhere.

Your customized prompt
Add transactional email notifications to this app for users events. Architecture: an outbox table in PostgreSQL written in the same transaction as the triggering change, a worker that polls the outbox and sends through the provider SDK, and a sent_at plus attempt count on each row so retries are bounded and idempotent. Templates live in emails/ as plain files with a subject line and text plus HTML parts; no template strings inline in application code. In development, route everything to a local capture that writes the rendered emails to disk instead of sending. Failure handling: provider errors requeue with backoff, permanently failing rows land in a dead-letter state I can query. Write tests that assert exactly one email per event even when the worker runs twice. Run the tests, then trigger one event locally and show me the rendered file on disk.

Same task in other tools

Questions about this prompt

Why route sends through an outbox table instead of calling the provider in the handler?

Because the outbox row commits in the same transaction as the change that caused it, a rollback sends nothing and a provider outage loses nothing. Inline sends fail in both directions and leave no queryable trace.

How do I add daily digest emails on top of this?

Add a scheduled worker that groups unsent outbox rows per user before rendering a digest template. The exactly-once test pattern still applies, asserted per digest run rather than per event.

How do I make sure test runs never email real users?

The dev capture writes rendered emails to disk instead of sending, and you can go further: have the provider client refuse to construct outside production without an explicit override flag, then confirm locally that events still produce files.

Related prompts