Backend
Email Service
Email integration with Resend and React Email
Email Service
TurboKit includes a complete email service using Resend for delivery and React Email for beautiful email templates.
Setup
Environment Variables
Add these to your .env file:
RESEND_API_KEY=re_your_api_key_here
FROM_EMAIL=noreply@yourdomain.com
APP_NAME=TurboKit
FRONTEND_URL=http://localhost:4100Get Your Resend API Key
- Sign up at resend.com
- Verify your domain or use the test domain
- Generate an API key from the dashboard
- Add it to your
.envfile
Email Templates
Email templates are created using React Email components in /apps/api/src/emails/.
Verification Email Template
// apps/api/src/emails/verification-email.tsx
import * as React from "react";
interface VerificationEmailProps {
userName: string;
verificationUrl: string;
}
export const VerificationEmail = ({
userName,
verificationUrl,
}: VerificationEmailProps) => (
<div style={{ fontFamily: "sans-serif", maxWidth: "580px" }}>
<h1>Verify your email</h1>
<p>Hi {userName},</p>
<p>Please verify your email address by clicking the button below.</p>
<a
href={verificationUrl}
style={{
backgroundColor: "#6366f1",
color: "white",
padding: "12px 32px",
textDecoration: "none",
borderRadius: "8px",
}}
>
Verify Email
</a>
</div>
);Email Service Functions
Send Verification Email
import { sendVerificationEmail } from "./email.service";
const result = await sendVerificationEmail({
email: "user@example.com",
name: "John Doe",
token: "verification_token_here",
});
if (result.success) {
console.log("Email sent successfully");
} else {
console.error("Failed to send email:", result.error);
}Send Password Reset Email
import { sendPasswordResetEmail } from "./email.service";
const result = await sendPasswordResetEmail({
email: "user@example.com",
name: "John Doe",
token: "reset_token_here",
});Email Flow
Registration Flow
- User registers with email and password
- Account is created in the database
- Verification token is generated and stored
- Verification email is sent with a link
- User clicks the link to verify their email
- Token is validated and email is marked as verified
- Welcome email is sent
Password Reset Flow
- User requests password reset
- Reset token is generated and stored (1 hour expiry)
- Password reset email is sent with a link
- User clicks the link and enters new password
- Token is validated and password is updated
- Token is deleted after use
Rate Limits
Resend has the following limits:
- Free Tier: 100 emails/day, 3,000 emails/month
- Pro Tier: Higher limits based on plan
Monitor your usage in the Resend dashboard.
Warning: Never commit your
RESEND_API_KEYto version control. Always use environment variables.