@convex-dev/resend component.
Prerequisites
Enable Email Feature
First, make sure email functionality is enabled in yourconfig.ts:
Setup Resend Account
- Create an account at Resend
- Generate an API key from the API Keys section
- For production, verify your domain in the Resend dashboard
Environment Variables Setup
Important: All email environment variables must be set in your Convex dashboard, not in your local.env.local file.
- Go to your Convex project dashboard
- Navigate to Settings > Environment Variables
- Add the following variables:
For testing, you can use
onboarding@resend.dev as the sender email. For production, verify your custom domain and use noreply@yourdomain.com.Testing Emails Locally
Using the Test Email Form
Kaizen includes a built-in test email form in the dashboard:-
Start your development server:
- Sign in to your application
- Navigate to the dashboard - you should see a “Test Email” form
-
Fill in the form with:
- To Email: Your email address
- Subject: Custom subject (optional)
- Message: Custom message (optional)
- Click “Send Test Email”
Using Convex Functions Directly
You can also test emails using Convex functions:Email Types and Templates
Welcome Email
Kaizen automatically sends welcome emails when new users sign up:Custom Email Templates
To add your own email templates, create new functions inconvex/sendEmails.ts:
Webhook Handling
Kaizen automatically handles Resend webhooks for email events:Setup Webhook in Resend Dashboard
- In your Resend dashboard, go to Webhooks
- Add a new webhook endpoint:
<your-convex-http-url>/resend-webhook - Select the events you want to track
- Copy the webhook secret and add it to your Convex environment variables
Email Event Processing
Email events are automatically processed:Production Setup
Domain Verification
For production use, you’ll need to verify your domain:- In Resend dashboard, go to Domains
- Add your domain (e.g.,
yourdomain.com) - Add the required DNS records to your domain provider
- Wait for verification (usually a few minutes)
- Update your
SENDER_EMAILto use your domain:noreply@yourdomain.com
Production Environment Variables
Update your production Convex environment with:Common Issues & Troubleshooting
Emails not being sent
- Check Convex environment variables: Ensure
RESEND_API_KEYis set in Convex dashboard, not local.env.local - Verify email feature is enabled: Check
config.tshasemail: trueandresend: { enabled: true } - Check Convex logs: Look for error messages in your Convex function logs
- Authentication required: Ensure user is authenticated when calling
sendTestEmailToAddress
Domain verification issues
- DNS propagation: Wait up to 24 hours for DNS changes to propagate
- Correct DNS records: Double-check you’ve added all required TXT, CNAME, and MX records
- Use verified domain: Only send from verified domains in production
Emails going to spam
- Domain authentication: Ensure SPF, DKIM, and DMARC records are properly configured
- Content quality: Avoid spam triggers (excessive exclamation marks, all caps, spam-like phrases)
- Sending reputation: Start with low volume and gradually increase
- List hygiene: Remove bounced emails and unsubscribed users
Webhook issues
- Correct endpoint: Ensure webhook URL is
<your-convex-http-url>/resend-webhook - Webhook secret: Verify
RESEND_WEBHOOK_SECRETmatches your Resend dashboard - Event selection: Choose the email events you want to track
Common Error Messages
“Must be authenticated to send test emails”- Solution: Ensure user is signed in before calling test email functions
- Solution: Verify your domain in Resend dashboard before sending from custom domain
- Solution: Check your
RESEND_API_KEYis correct and active
For transactional emails, always provide a clear way for users to manage their email preferences or unsubscribe. Consider implementing an email preferences page in your dashboard.
Email Best Practices
Template Design
- Use responsive HTML templates
- Include both HTML and plain text versions
- Keep subject lines under 50 characters
- Use clear call-to-action buttons
Deliverability
- Implement double opt-in for marketing emails
- Monitor bounce rates and remove invalid emails
- Include proper unsubscribe links
- Use consistent sender names and email addresses
Performance
- Send emails asynchronously using Convex schedulers
- Batch process large email lists
- Implement retry logic for failed sends
- Monitor email metrics and adjust strategies accordingly