Welcome to the Jose Madrid Salsa developer docs — explore features, APIs, and deployment guides.
Jose Madrid SalsaJMS Docs

Email

Email service integration using Resend with React Email templates

Email Integration

The platform sends emails through Resend using React Email templates. The email system supports transactional emails (order confirmations, shipping notifications), marketing emails (campaigns, newsletters), and administrative emails (password resets, admin replies).

Architecture

The email system is split across two main modules:

  • lib/email.ts -- Simple email functions (admin replies, password resets, generic sends)
  • lib/email/client.ts -- Full-featured email client with React Email rendering, logging, and unsubscribe checking
Email Request -> Unsubscribe Check -> React Email Render -> Resend API -> Email Log

Environment Variables

VariableDescriptionRequired
RESEND_API_KEYResend API key (re_xxx)Yes
FROM_EMAILSender email addressNo (defaults to orders@josemadridsalsa.com)
NEXT_PUBLIC_BASE_URLBase URL for unsubscribe linksYes
NEXTAUTH_URLUsed for password reset linksYes

If RESEND_API_KEY is not set, all email functions gracefully skip sending and return { skipped: true }. This allows development without a Resend account.

Setup

Create a Resend account

Sign up at resend.com and generate an API key.

Verify your domain

Add DNS records to verify your sending domain in the Resend dashboard.

Configure environment variables

RESEND_API_KEY=re_...
FROM_EMAIL=orders@josemadridsalsa.com
NEXT_PUBLIC_BASE_URL=https://josemadrid.net

Simple Email Functions (lib/email.ts)

sendAdminReplyEmail(to, subject, message)

Sends a reply from the admin panel. Attempts to load a customizable admin_reply template from the database (Prisma EmailTemplate model). Falls back to plain text if no template exists.

sendPasswordResetEmail(email, token)

Sends a branded HTML password reset email with:

  • Reset link (expires in 1 hour)
  • Copy-paste URL fallback
  • Jose Madrid Salsa branding with gradient header

sendEmail(options)

Generic email sender accepting to, subject, html, and text fields.

React Email Client (lib/email/client.ts)

sendEmail(options)

The full-featured email sender:

await sendEmail({
  to: 'customer@example.com',
  subject: 'Order Confirmed',
  react: <OrderConfirmationEmail order={order} />,
  type: 'order-confirmation',
  orderId: order.id,
  userId: user.id,
})

Features:

  • React Email rendering: Converts React components to HTML via @react-email/render
  • Unsubscribe checking: Non-transactional emails check checkUnsubscribed() before sending
  • List-Unsubscribe header: Compliant List-Unsubscribe and List-Unsubscribe-Post headers for one-click unsubscribe
  • Email logging: Every send (success or failure) is logged via logEmailSend()
  • Privacy: Email addresses are SHA-256 hashed (first 12 chars) in log output

Transactional vs. Marketing

Transactional emails are always sent regardless of unsubscribe status:

  • order-confirmation
  • shipping-notification
  • delivery-confirmation

All other email types respect unsubscribe preferences.

Email System Components

The lib/email/ directory contains a comprehensive email infrastructure:

FilePurpose
client.tsReact Email rendering and sending
automation.tsAutomated email triggers (order confirmation, etc.)
automation-engine.tsCampaign automation engine
campaign-sender.tsBulk campaign email sender
sender.tsLow-level sending logic
queue.tsEmail queue management
rate-limit.tsRate limiting for bulk sends
suppression.tsSuppression list management
logger.tsEmail send logging
templates.tsTemplate management
template-library.tsPre-built template library
types.tsEmail type definitions
blocks/Reusable email template blocks
templates/React Email template components

Key Files

FilePurpose
lib/email.tsSimple email functions
lib/email/client.tsFull-featured React Email client
app/api/send-email/Email sending API endpoint
app/api/webhooks/resend/Resend webhook handler

How is this guide?

Edit on GitHub

Last updated on

On this page