Section 11 of 14
Email Notifications
What This Does
The app sends 8 types of email notifications via Resend (an email API service). Error alerts, review needed, plan limit warnings, ShipStation disconnect reminders, price discrepancy alerts, daily/weekly review digests, and split shipment notices. Each has an HTML template for visual emails and a plain text fallback.
Why It Matters
Merchants need to know what's happening with their orders without logging into the app constantly. Error emails help them fix issues fast. Review emails prompt them to approve corrections. Plan limit warnings prevent unexpected processing stops.
How It Works
- 1.The sendOrderAlert() function is the single entry point — you pass it an alert type and context data.
- 2.Each alert type has its own template function that generates subject, HTML, and plain text.
- 3.All templates use a shared baseLayout() for consistent email branding (Declared header, unsubscribe footer).
- 4.All user-provided data is escaped with escapeHtml() to prevent XSS in email clients.
- 5.Email delivery uses Resend's API — we pass the HTML, subject, and recipient, and Resend handles SMTP delivery.
- 6.Notification preferences on the Shop model control which emails are sent (notifyOnError, notifyOnPlanLimit, reviewNotifyFrequency, etc.).
The Code
Key Decisions
- ●8 distinct email types rather than one generic template — each email is purpose-built with relevant context and CTAs.
- ●All emails include deep links back to the relevant section of the app (orders page, review queue, settings, billing).
- ●Review digest emails (DAILY/WEEKLY) are sent by the cron worker, not triggered by individual orders.
What Could Go Wrong
- ●If Resend is down, email sending fails — but this is caught and logged, and doesn't block order processing.
- ●If the merchant's notify email is invalid, Resend returns an error which we log and continue.