Skip to main content

Overview

PyqDeck uses Resend for email delivery and Mailgen for HTML email template generation. The system is implemented but not yet wired into the application’s routes/controllers.

Configuration

Environment Variables

Setup (backend/src/config/mail.config.js)

Key design decision: If no RESEND_API_KEY is set, resendClient is null and all email functions become no-ops. This allows the app to run locally without email configuration.

Email Types

Three email functions are available in backend/src/services/mail.service.js:

1. Verification Email (OTP)

2. Welcome Email

3. Password Reset Email (OTP)

How Templates Work

There are no static HTML template files. All email templates are generated dynamically via Mailgen’s API at runtime.

OTP Emails (Action-based)

Mailgen renders this into a responsive HTML email with the OTP displayed as a prominent action button.

Welcome Email (Text-based)

Sending the Email

Each email is sent with both HTML and plain text versions for maximum compatibility.

Error Handling

All three functions follow the same pattern:
  • No API key → returns immediately (no error)
  • Send fails → logs error + throws (caller must handle)
  • Success → logs confirmation

Current Status: Not Yet Wired In

The email service functions are implemented but not called anywhere in the application. No controller, route, or service imports from mail.service.js.

Where They Should Be Connected

Example: Wiring into Clerk Webhook

Resend Setup

Getting an API Key

  1. Sign up at resend.com
  2. Create an API key from the dashboard
  3. Free tier: 3,000 emails/month, 100 emails/day

Domain Verification

For production, verify your domain in Resend to:
  • Remove the “via resend.net” footer
  • Use your own from address (e.g., noreply@pyqdeck.in)
  • Improve email deliverability
Add the provided DNS records (SPF, DKIM, DMARC) to your domain registrar.

Testing Locally

Resend provides a test mode where emails are logged but not actually sent. Use the test API key (re_123456789) for local development.

Testing

The email service has full test coverage:

Happy Path Tests

Error Path Tests

No-Config Tests

Future Enhancements

When wiring the email system into the app, consider:
  1. Email queue — Use a queue (Bull, Redis) to handle email sending asynchronously
  2. Email templates — Create custom Mailgen themes or switch to a more flexible template engine for complex emails
  3. Email analytics — Track open rates, click rates via Resend’s analytics API
  4. Additional email types — Notification emails, study reminders, paper update alerts
  5. OTP storage — Store OTPs with expiry in Redis or MongoDB for verification

Next Steps