The MediQueue app now has a comprehensive email notification system using Resend with automated appointment reminders, confirmations, and cancellation notifications.
Professional HTML email templates for:
- ✉️ Appointment Confirmation - Sent immediately after booking
- ⏰ Appointment Reminders - Automated reminders (24hr, 2hr, 15min before)
- 🔔 Queue Position Updates - Real-time queue status notifications
- ❌ Appointment Cancellations - Sent when appointments are cancelled
- 👋 Welcome Email - Sent to new users upon registration
- Cron Job: Runs every 5 minutes via Vercel Cron
- Reminder Intervals: 24 hours, 2 hours, 15 minutes before appointment
- Duplicate Prevention: Tracks sent reminders in database
- Batch Processing: Efficiently handles multiple appointments
- User Control: Patients can enable/disable different notification types
- Channel-Specific: Separate preferences for email, SMS, WhatsApp, push
- Granular Control: Control for confirmations, reminders, queue updates, cancellations
- Go to https://resend.com
- Create a free account
- Navigate to API Keys section
- Click Create API Key
- Copy your API key
Add these to your .env.local file:
# Resend Email Configuration
RESEND_API_KEY=re_xxxxxxxxxxxxxxxxxxxxxxxxxx
EMAIL_FROM=MediQueue <noreply@yourdomain.com>
EMAIL_REPLY_TO=support@mediqueue.com
# Cron Secret (generate a random string)
CRON_SECRET=your_random_secret_string_hereRun the SQL commands in DATABASE_UPDATES.sql in your Supabase SQL Editor:
# The file contains:
# 1. appointment_reminders table
# 2. Indexes for performance
# 3. RLS policies
# 4. notification_preferences column for patientsImportant Tables:
appointment_reminders- Tracks all sent reminders to prevent duplicatespatients.notification_preferences- Stores user notification settings (JSONB)
For production emails with your custom domain:
- In Resend Dashboard, go to Domains
- Click Add Domain
- Enter your domain (e.g.,
mediqueue.com) - Add the provided DNS records to your domain provider
- Wait for verification (usually 15 minutes)
- Update
EMAIL_FROMin.env.local:EMAIL_FROM=MediQueue <noreply@mediqueue.com>
- Push your code to GitHub
- Deploy to Vercel
- Vercel will automatically configure the cron job from
vercel.json - Add environment variables in Vercel project settings
- Book an appointment through the app
- Check the email inbox for confirmation
- Verify all details are correct
- Create a test appointment 30 minutes in the future
- Wait for the cron job to run (every 5 minutes)
- Check for 15-minute reminder email
- Cancel a confirmed appointment
- Check email for cancellation confirmation
1. User books appointment
↓
2. Appointment created in database
↓
3. API call to /api/send-email/confirmation
↓
4. Email sent via Resend
↓
5. User receives confirmation email
1. Vercel Cron triggers /api/cron/send-reminders (every 5 min)
↓
2. Query appointments in reminder windows (24hr, 2hr, 15min)
↓
3. Check if reminder already sent (appointment_reminders table)
↓
4. Check patient notification preferences
↓
5. Send reminder emails via Resend
↓
6. Record sent reminders in database
1. User cancels appointment
↓
2. Appointment status updated to 'cancelled'
↓
3. API call to /api/send-email/cancellation
↓
4. Email sent via Resend
↓
5. User receives cancellation confirmation
Send appointment confirmation email.
Request Body:
{
"appointmentId": "uuid"
}Send appointment cancellation email.
Request Body:
{
"appointmentId": "uuid",
"cancellationReason": "Patient requested cancellation"
}Automated cron job for sending reminders (protected by CRON_SECRET).
Headers:
Authorization: Bearer your_cron_secret
{
"email": {
"enabled": true,
"appointment_confirmation": true,
"appointment_reminder": true,
"queue_updates": true,
"cancellations": true
},
"sms": {
"enabled": false,
"appointment_reminder": true,
"queue_updates": true
},
"whatsapp": {
"enabled": false,
"appointment_reminder": true,
"queue_updates": true
},
"push": {
"enabled": false,
"appointment_reminder": true,
"queue_updates": true
}
}- Go to Vercel Dashboard
- Select your project
- Navigate to Logs
- Filter by
/api/cron/send-reminders
- Go to Resend Dashboard
- Navigate to Emails
- View all sent emails, delivery status, and errors
View sent reminders:
SELECT * FROM appointment_reminders
ORDER BY sent_at DESC
LIMIT 50;Check upcoming appointments needing reminders:
SELECT
a.id,
a.token_number,
a.scheduled_time,
EXTRACT(EPOCH FROM (a.scheduled_time - NOW())) / 3600 as hours_until
FROM appointments a
WHERE a.status = 'confirmed'
AND a.scheduled_time > NOW()
AND a.scheduled_time < NOW() + INTERVAL '25 hours'
ORDER BY a.scheduled_time;Check patient notification preferences:
SELECT
u.email,
p.notification_preferences
FROM patients p
JOIN users u ON p.user_id = u.id
LIMIT 10;- 100 emails/day for free
- 3,000 emails/month for free
- For production, consider upgrading to paid plan
- ✅ Check
RESEND_API_KEYis set correctly - ✅ Verify domain is verified (for production)
- ✅ Check Resend dashboard for error messages
- ✅ Ensure patient has email address in database
- ✅ Check notification preferences are enabled
- ✅ Verify
vercel.jsonis deployed - ✅ Check Vercel cron job is active
- ✅ Verify
CRON_SECRETis set - ✅ Check database has
appointment_reminderstable - ✅ Review cron job logs for errors
- The system prevents duplicates via
appointment_reminderstable - Check the unique index:
idx_unique_reminder
- Update
src/app/(auth)/register/page.tsx - Call email service after successful registration
- Send welcome email to new users
- Similar structure to email system
- Add Twilio integration
- Update notification preferences
- Use Twilio WhatsApp API
- Integrate with existing notification system
src/
├── lib/
│ └── email/
│ ├── resend.ts # Resend client initialization
│ ├── templates.tsx # Email HTML templates
│ └── email-service.ts # Email sending functions
├── app/
│ └── api/
│ ├── cron/
│ │ └── send-reminders/
│ │ └── route.ts # Automated reminder cron job
│ └── send-email/
│ ├── confirmation/
│ │ └── route.ts # Confirmation email API
│ └── cancellation/
│ └── route.ts # Cancellation email API
└── vercel.json # Cron job configuration
For issues or questions:
- Check Resend documentation: https://resend.com/docs
- Review Vercel Cron docs: https://vercel.com/docs/cron-jobs
- Email: support@mediqueue.com
🎉 Email Notification System is Ready!
The system is now fully integrated and will automatically send:
- ✅ Confirmation emails on booking
- ✅ Automated reminders (24hr, 2hr, 15min)
- ✅ Cancellation confirmations
- ✅ Queue position updates (when implemented)