BoilerPrompt
Replit Agent

Replit Agent prompt to add email notifications

Email code written inline in route handlers is where delivery bugs hide. This prompt makes Replit Agent build an outbox table with a retrying worker, dev-mode console rendering, and an unsubscribe flag that digests respect. You end up with notifications you can watch move through the database pane instead of hoping the send worked.

Last updated

Prompt
Add transactional email notifications to the app in this Repl. Tell me which email provider integration you intend to use before building. Whichever it is, the API key lives in Secrets and the sender address is one config value, not a literal scattered through the code.

Events to cover: a welcome message on signup, a confirmation when credentials change, and a weekly digest, each with its own template.

Architecture: do not send inline from request handlers. Write an outbox table in the built-in Postgres database with event type, recipient, payload, status, attempt count, and last_error. A worker loop drains it, retries failures with backoff up to three attempts, then marks the row dead so nothing loops forever.

Templates: plain HTML with a text fallback, shared header and footer partials, and an unsubscribe link on anything non-essential that flips a flag on the user row. The digest respects that flag, credential notices ignore it deliberately.

Dev behavior: when no provider key is present, log the rendered email to the console and mark the outbox row sent_dev so I can build without an account. Never attempt a real send in that mode.

Failure UX: sending problems never surface as signup errors, the account gets created regardless and the outbox owns delivery.

Done when: I trigger a signup in the webview, watch the outbox row move from pending to sent in the database pane, see the rendered text fallback in the console in dev mode, and can walk the unsubscribe flow end to end.

Same task in other tools

Questions about this prompt

What happens in development with no provider key?

The worker renders the email, logs it to the console, and marks the outbox row sent_dev. Nothing real is sent, so you can build and test every trigger before creating a provider account or adding a key to Secrets.

How do I add a new notification type later?

Add a template, then enqueue an outbox row at the event site. The worker needs no changes. The one decision each time is whether the unsubscribe flag applies, essential account notices should ignore it.

Rows are stuck at pending in the outbox, what do I check?

Either the worker loop is not running or it crashes before updating status. The attempt count and last_error columns exist for exactly this, read them in the database pane and hand the error text back to the agent.

Related prompts