Lovable prompt to add email notifications
Email is a side effect, and the classic mistake is letting a failed send break the action that triggered it. This prompt has Lovable route every message through one edge function with logging, per-user preferences, and tokenized unsubscribe links, giving you transactional email you can audit from an email_log table.
Last updated
Add transactional email notifications to this app through a single edge function named send-email that talks to Resend using an API key stored as a Supabase secret. Events to wire: a welcome email after signup confirmation, a notification when someone comments on a record you own, and a weekly digest sent by a scheduled function that skips users with nothing to report. Preferences: a notification_settings table with a per-user boolean for each event type, defaulted on, editable from a settings screen with instant saves. Every email footer carries an unsubscribe link containing a signed token that flips the matching boolean without requiring login. Reliability: log every attempt to an email_log table with recipient, template, status, and provider error text, retry a failed send once, and never let a failed email break the user-facing action that triggered it. Posting a comment must succeed even when the notification fails. Templates: a shared header and footer, plain readable HTML with a single button per message, and a preview route under /admin/emails that renders each template with sample data. States: the settings screen confirms each toggle save inline, and the admin preview shows a clear notice when the Resend secret is missing instead of rendering a blank page. Acceptance: toggling comment emails off stops that type while the digest still arrives, the unsubscribe link works from a logged-out browser, email_log holds a row with status for every attempted send, and deleting a user stops all sends to that address.
Same task in other tools
Questions about this prompt
Do I need my own Resend account first?
Yes. Create it, verify a sending domain, and add the API key as a Supabase secret when Lovable asks. Until the domain verifies, delivery to addresses other than your own is typically blocked by the provider.
How do I add a new notification type later?
Ask Lovable for the trigger, a template, and a new boolean on notification_settings in one prompt, and remind it to route through send-email so logging stays centralized.
The digest still reaches users who opted out. Why?
The scheduled function is probably querying all users and ignoring the preference join. Have Lovable filter on the digest boolean inside the query itself, not in a later loop, and check email_log to confirm.