Email service is optional but required for password reset, email verification, and account deletion features.
Email Configuration
Both environment variables must be set to enable email features:API key for the email service provider.Example:
re_abc123def456... (Resend)Required: Yes (if using email features)Email address that emails will be sent from.Example:
[email protected], [email protected]Required: Yes (if using email features)Note: Must be a verified domain with your email provider.Email Provider
Budgetron uses Resend as the default email provider. Resend offers:- Simple API integration
- Free tier: 100 emails/day, 3,000/month
- Excellent deliverability
- Domain verification
Setting Up Resend
- Sign up at resend.com
- Verify your domain:
- Add DNS records provided by Resend
- Wait for verification (usually instant)
- Generate an API key in the dashboard
- Set environment variables:
Domain Verification
Add these DNS records to your domain:| Type | Name | Value |
|---|---|---|
| TXT | @ | resend-verification=your-value |
| MX | @ | feedback-smtp.resend.com (priority 10) |
| TXT | _dmarc | v=DMARC1; p=none |
Email Templates
Budgetron includes React-based email templates for all notification types:Available Templates
Welcome Email
Sent when a new user creates an account.Template:
src/emails/welcome-email.tsxTrigger: User registrationEmail Verification
Sent after sign-up with verification link.Template:
src/emails/email-verification-email.tsxTrigger: New account creationExpires: 15 minutesPassword Reset
Sent when user requests password reset.Template:
src/emails/reset-password-email.tsxTrigger: Forgot passwordExpires: 15 minutesDelete Account
Sent when user requests account deletion.Template:
src/emails/delete-account-email.tsxTrigger: Delete account requestExpires: 15 minutesTemplate Features
- Built with React components
- Responsive design
- Consistent branding
- Secure, expiring links
- Inline CSS for email client compatibility
Email Workflows
User Registration Flow
- User signs up with email and password
- Welcome email sent immediately
- Email verification sent with 15-minute token
- User clicks verification link
- Email marked as verified, auto sign-in
Password Reset Flow
- User clicks “Forgot password”
- Password reset email sent with 15-minute token
- User clicks reset link
- User enters new password
- Password updated, token invalidated
Account Deletion Flow
- User requests account deletion
- Delete account email sent with 15-minute confirmation token
- User clicks confirmation link
- Account and all data deleted permanently
Service Implementation
The email service is implemented insrc/server/email/service.ts:
Service Detection
The application checks if email is enabled at runtime usingisEmailServiceEnabled() defined in src/server/email/utils.ts. Both environment variables must be set for the service to be active.
Provider Abstraction
The provider is abstracted insrc/server/email/provider.ts using a singleton pattern. This allows for easy replacement with another email provider by modifying the provider file.
Using Alternative Email Providers
While Resend is the default, you can integrate any email provider by modifying
src/server/email/provider.ts.Supported Alternatives
SendGrid
SendGrid
Popular email API with free tier.Setup:
- Install:
npm install @sendgrid/mail - Replace Resend in provider.ts
- Update environment variables
Mailgun
Mailgun
Powerful email API for developers.Setup:
- Install:
npm install mailgun.js - Replace Resend in provider.ts
- Update environment variables
AWS SES
AWS SES
Scalable email service by Amazon.Setup:
- Install:
npm install @aws-sdk/client-ses - Replace Resend in provider.ts
- Configure AWS credentials
Postmark
Postmark
Reliable transactional email.Setup:
- Install:
npm install postmark - Replace Resend in provider.ts
- Update environment variables
Implementation Steps
- Install the provider’s SDK
- Update
src/server/email/provider.ts: - Update
src/server/email/service.tsto match provider’s API - Test all email workflows
Troubleshooting
Emails Not Sending
Service Not Enabled
Service Not Enabled
Error: “Email service is not enabled”Solution: Verify both environment variables are set:Both must return non-empty values.
Domain Not Verified
Domain Not Verified
Error: “Domain not verified” or “Forbidden”Solutions:
- Verify domain in Resend dashboard
- Check DNS records are properly configured
- Wait up to 48 hours for DNS propagation
- Use Resend’s testing domain for development
Invalid API Key
Invalid API Key
Error: “Invalid API key” or “Unauthorized”Solutions:
- Verify
EMAIL_PROVIDER_API_KEYis correct - Generate new API key in Resend dashboard
- Check for extra spaces or characters
Invalid From Address
Invalid From Address
Error: “Invalid from address”Solutions:
- Ensure
EMAIL_PROVIDER_FROM_EMAILuses verified domain - Format:
[email protected](no spaces) - Must match domain verified in Resend
Rate Limit Exceeded
Rate Limit Exceeded
Error: “Rate limit exceeded” or “Too many requests”Solutions:
- Check Resend rate limits (100/day on free tier)
- Upgrade to higher tier if needed
- Implement rate limiting in application
Testing Email Configuration
Test your email setup:id field.
Emails Going to Spam
Solutions:- Verify domain with email provider
- Add SPF record:
v=spf1 include:resend.com ~all - Configure DKIM (automatic with Resend)
- Add DMARC policy:
v=DMARC1; p=quarantine - Use a dedicated sending domain
- Avoid spam trigger words
Development and Testing
Development Workflow
For local development without email setup:- Leave email variables empty
- Features requiring email will be disabled
- Users can still sign in with email/password
- OAuth sign-in works independently
Testing Emails Locally
- Resend Test Mode
- Mailtrap
- Local SMTP Server
Use Resend’s onboarded domain for testing:Emails will be sent but won’t deliver to recipients.
Email Deliverability
Best Practices
Follow these guidelines for optimal email deliverability:
- Verify domain - Always verify your sending domain
- Use dedicated domain - Don’t send from your main domain
- Configure DNS - Set up SPF, DKIM, and DMARC
- Warm up domain - Gradually increase sending volume
- Monitor bounces - Track and handle bounce rates
- Clean subject lines - Avoid spam trigger words
- Include unsubscribe - For non-transactional emails
DNS Configuration
Required DNS records for Resend:Rate Limits and Pricing
Resend Pricing (as of 2024)
| Plan | Price | Emails/Month | Features |
|---|---|---|---|
| Free | $0 | 3,000 | 100/day, 1 domain |
| Pro | $20 | 50,000 | Unlimited domains, analytics |
| Business | $80 | 200,000 | Priority support, SLA |
The free tier is sufficient for most small to medium deployments.
Privacy and Compliance
Data Handling
- Email content: Sent to Resend via HTTPS
- User data: Only email addresses sent to provider
- Retention: Resend stores logs for 30 days
- GDPR: Resend is GDPR compliant
User Privacy
- All email links expire after 15 minutes
- Tokens are single-use only
- No tracking pixels in emails
- Plain text alternative included
Related Configuration
- Authentication Configuration - Email verification and password reset
- Environment Variables - Complete environment reference