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
| Variable | Example | Purpose |
|---|---|---|
RESEND_API_KEY | re_abc123... | Resend API authentication key |
MAIL_FROM | onboarding@resend.dev | Sender “from” address |
APP_NAME | PyqDeck | Product name displayed in email templates |
APP_URL | https://pyqdeck.in | Product link in email footer |
Setup (backend/src/config/mail.config.js)
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 inbackend/src/services/mail.service.js:
1. Verification Email (OTP)
| Property | Value |
|---|---|
| Subject | "Verify Your Email" |
| Content | ”Use the following OTP to verify your email:“ |
| Button color | Green (#22BC66) |
| Display | OTP code as button text |
2. Welcome Email
| Property | Value |
|---|---|
| Subject | "Welcome to Our Platform" |
| Content | "Welcome ${name}! We're glad to have you on board." |
| Outro | ”Feel free to reach out if you have any questions.” |
| CTA | Link to the app via APP_URL |
3. Password Reset Email (OTP)
| Property | Value |
|---|---|
| Subject | "Reset Your Password" |
| Content | ”Use the following OTP to reset your password:“ |
| Button color | Red (#FF0000) |
| Display | OTP code as button text |
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)
Welcome Email (Text-based)
Sending the Email
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 frommail.service.js.
Where They Should Be Connected
| Email Type | Suggested Trigger Point |
|---|---|
| Verification OTP | After user signs up, before Clerk confirms email |
| Welcome Email | After user.created Clerk webhook event |
| Password Reset OTP | When user requests password reset |
Example: Wiring into Clerk Webhook
Resend Setup
Getting an API Key
- Sign up at resend.com
- Create an API key from the dashboard
- 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
fromaddress (e.g.,noreply@pyqdeck.in) - Improve email deliverability
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:- Email queue — Use a queue (Bull, Redis) to handle email sending asynchronously
- Email templates — Create custom Mailgen themes or switch to a more flexible template engine for complex emails
- Email analytics — Track open rates, click rates via Resend’s analytics API
- Additional email types — Notification emails, study reminders, paper update alerts
- OTP storage — Store OTPs with expiry in Redis or MongoDB for verification
Next Steps
- Explore the auth flow
- Review the data pipeline
- Check monitoring setup

