TurboKit
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:4100

Get Your Resend API Key

  1. Sign up at resend.com
  2. Verify your domain or use the test domain
  3. Generate an API key from the dashboard
  4. Add it to your .env file

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

  1. User registers with email and password
  2. Account is created in the database
  3. Verification token is generated and stored
  4. Verification email is sent with a link
  5. User clicks the link to verify their email
  6. Token is validated and email is marked as verified
  7. Welcome email is sent

Password Reset Flow

  1. User requests password reset
  2. Reset token is generated and stored (1 hour expiry)
  3. Password reset email is sent with a link
  4. User clicks the link and enters new password
  5. Token is validated and password is updated
  6. 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_KEY to version control. Always use environment variables.

On this page