<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged react-email</title>
<link>https://coderlegion.com/tag/react-email</link>
<description>Powered by Question2Answer</description>
<item>
<title>How to Setup Resend Email in Next.js 16 (2026 Complete Beginner Guide)</title>
<link>https://coderlegion.com/23215/how-to-setup-resend-email-in-next-js-16-2026-complete-beginner-guide</link>
<description>&lt;p&gt;Sending emails is one of the most common requirements in modern web applications.&lt;/p&gt;
&lt;p&gt;Whether you're building:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A contact form&lt;/li&gt;
&lt;li&gt;Authentication system&lt;/li&gt;
&lt;li&gt;SaaS application&lt;/li&gt;
&lt;li&gt;Newsletter platform&lt;/li&gt;
&lt;li&gt;E-commerce store&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You'll eventually need a reliable way to send emails.&lt;/p&gt;
&lt;p&gt;In the past, developers often relied on SMTP providers and complicated email configurations. Today, services like Resend make email delivery significantly easier with a modern API-first approach.&lt;/p&gt;
&lt;p&gt;In this guide, you'll learn how to integrate Resend with Next.js 16 using the App Router, create a contact form, send transactional emails, build reusable React Email templates, verify your domain, and deploy everything to production.&lt;/p&gt;
&lt;p&gt;By the end of this tutorial you'll know how to:&lt;/p&gt;
&lt;p&gt;✅ Create a Resend account&lt;br&gt;
✅ Generate API keys&lt;br&gt;
✅ Send emails using API Routes&lt;br&gt;
✅ Send emails using Server Actions&lt;br&gt;
✅ Create React Email templates&lt;br&gt;
✅ Verify a custom domain&lt;br&gt;
✅ Deploy to Vercel&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-we-ll-build&quot;&gt;What We'll Build&lt;/h3&gt;
&lt;p&gt;Here's the flow we'll create:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;   User submits form
           ↓
Server Action / API Route
           ↓
      Resend API
           ↓
      User Inbox
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://devstacked.tech/resend-nextjs16/image1.png&quot; alt=&quot;Resend Nextjs Email Form&quot;&gt;&lt;/p&gt;
&lt;p&gt;When a visitor submits their email address, Next.js will securely send a request to Resend, which then delivers the email to the recipient.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-is-resend-&quot;&gt;What is Resend?&lt;/h3&gt;
&lt;p&gt;Resend is a modern transactional email platform built specifically for developers.&lt;/p&gt;
&lt;p&gt;Unlike traditional SMTP providers, Resend offers a simple API that allows you to send emails with minimal configuration.&lt;/p&gt;
&lt;p&gt;Some of its key features include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Simple API integration&lt;/li&gt;
&lt;li&gt;React Email support&lt;/li&gt;
&lt;li&gt;Fast email delivery&lt;/li&gt;
&lt;li&gt;Email analytics&lt;/li&gt;
&lt;li&gt;Domain verification&lt;/li&gt;
&lt;li&gt;Excellent developer experience&lt;/li&gt;
&lt;li&gt;Great documentation&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Common use cases include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Contact forms&lt;/li&gt;
&lt;li&gt;Welcome emails&lt;/li&gt;
&lt;li&gt;Password reset emails&lt;/li&gt;
&lt;li&gt;OTP verification emails&lt;/li&gt;
&lt;li&gt;SaaS notifications&lt;/li&gt;
&lt;li&gt;E-commerce receipts&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;why-use-resend-instead-of-smtp-&quot;&gt;Why Use Resend Instead of SMTP?&lt;/h3&gt;
&lt;p&gt;Traditional SMTP setups can become frustrating.&lt;/p&gt;
&lt;p&gt;You often need to configure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SMTP servers&lt;/li&gt;
&lt;li&gt;Ports&lt;/li&gt;
&lt;li&gt;Authentication&lt;/li&gt;
&lt;li&gt;SSL/TLS settings&lt;/li&gt;
&lt;li&gt;Email clients&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Resend eliminates most of this complexity.&lt;/p&gt;
&lt;p&gt;Instead of configuring SMTP manually, you simply send a request like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;await resend.emails.send({
  from: &quot;Acme &amp;lt;*Emails are not allowed*&amp;gt;&quot;,
  to: &quot;*Emails are not allowed*&quot;,
  subject: &quot;Hello World&quot;,
  html: &quot;&amp;lt;p&amp;gt;Hello from Resend&amp;lt;/p&amp;gt;&quot;,
});
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;resend-vs-smtp&quot;&gt;Resend vs SMTP&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Feature              &lt;/th&gt;&lt;th&gt;Resend    &lt;/th&gt;&lt;th&gt;Traditional SMTP&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Easy Setup           &lt;/td&gt;&lt;td&gt;✅         &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;API-Based            &lt;/td&gt;&lt;td&gt;✅         &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;React Email Support  &lt;/td&gt;&lt;td&gt;✅         &lt;/td&gt;&lt;td&gt;❌&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Analytics            &lt;/td&gt;&lt;td&gt;✅         &lt;/td&gt;&lt;td&gt;Limited&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Developer Experience &lt;/td&gt;&lt;td&gt;Excellent &lt;/td&gt;&lt;td&gt;Average&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Modern Documentation &lt;/td&gt;&lt;td&gt;✅         &lt;/td&gt;&lt;td&gt;Varies&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h3 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;
&lt;p&gt;Before getting started, make sure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Node.js installed&lt;/li&gt;
&lt;li&gt;Basic React knowledge&lt;/li&gt;
&lt;li&gt;Basic Next.js knowledge&lt;/li&gt;
&lt;li&gt;VS Code or another editor&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Recommended:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Custom domain&lt;/li&gt;
&lt;li&gt;Vercel account&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;create-a-next-js-16-project&quot;&gt;Create a Next.js 16 Project&lt;/h3&gt;
&lt;p&gt;Create a new Next.js application:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npx create-next-app@latest resend-email-guide
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For this tutorial, choose:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;TypeScript&lt;/li&gt;
&lt;li&gt;Tailwind CSS&lt;/li&gt;
&lt;li&gt;React Compiler&lt;/li&gt;
&lt;li&gt;src directory&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Move into the project:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;cd resend-email-guide
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Start the development server:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;why-these-options-&quot;&gt;Why These Options?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;TypeScript&lt;/strong&gt; improves code quality and catches errors early.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tailwind CSS&lt;/strong&gt; speeds up UI development.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;App Router&lt;/strong&gt; is the recommended routing system in Next.js 16.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;React Compiler&lt;/strong&gt; automatically memoizes components and hooks to eliminate unnecessary re-renders.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;install-resend&quot;&gt;Install Resend&lt;/h3&gt;
&lt;p&gt;Install the official Resend SDK:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install resend
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This package allows your application to communicate with the Resend API.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;create-a-resend-account&quot;&gt;Create a Resend Account&lt;/h3&gt;
&lt;p&gt;Visit:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;https://resend.com
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create an account&lt;/li&gt;
&lt;li&gt;Verify your email address&lt;/li&gt;
&lt;li&gt;Open the dashboard&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h4 id=&quot;generate-a-resend-api-key&quot;&gt;Generate a Resend API Key&lt;/h4&gt;
&lt;p&gt;Inside the Resend dashboard:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open API Keys&lt;/li&gt;
&lt;li&gt;Click Create API Key&lt;/li&gt;
&lt;li&gt;Copy the generated key&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Create a &lt;code&gt;.env.local&lt;/code&gt; file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-env&quot;&gt;RESEND_API_KEY=your_api_key_here
&lt;/code&gt;&lt;/pre&gt;
&lt;blockquote&gt;&lt;p&gt;Never expose your API key in client-side code. API keys should only be used on the server.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;hr&gt;
&lt;h3 id=&quot;create-a-reusable-resend-client&quot;&gt;Create a Reusable Resend Client&lt;/h3&gt;
&lt;p&gt;Instead of creating a new Resend instance everywhere, create a reusable client.&lt;/p&gt;
&lt;p&gt;Create:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;src/lib/resend.ts
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;import { Resend } from &quot;resend&quot;;

export const resend = new Resend(
  process.env.RESEND_API_KEY
);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now you can import this client throughout your application.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;create-your-first-email-api-route&quot;&gt;Create Your First Email API Route&lt;/h3&gt;
&lt;p&gt;Create:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;src/app/api/send/route.ts
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Add the following code:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;import { isValidEmail } from &quot;@/lib/helpers&quot;;
import { resend } from &quot;@/lib/resend&quot;;

export async function POST(request: Request) {
  const { email } = await request.json();

  if (!email) {
    return Response.json(
      { error: &quot;Email is required&quot; },
      { status: 400 }
    );
  }

  if (!isValidEmail(email)) {
    return Response.json(
      { error: &quot;Please enter a valid email&quot; },
      { status: 400 }
    );
  }

  try {
    const data = await resend.emails.send({
      from: &quot;*Emails are not allowed*&quot;,
      to: email,
      subject: &quot;Hello from Next.js 16&quot;,
      html: &quot;&amp;lt;p&amp;gt;Email sent successfully!&amp;lt;/p&amp;gt;&quot;,
    });

    return Response.json(data);
  } catch (error) {
    return Response.json({ error });
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;understanding-the-code&quot;&gt;Understanding the Code&lt;/h3&gt;
&lt;h4 id=&quot;creating-the-email-request&quot;&gt;Creating the Email Request&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;await resend.emails.send(...)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This sends an email through the Resend API.&lt;/p&gt;
&lt;h4 id=&quot;returning-responses&quot;&gt;Returning Responses&lt;/h4&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;Response.json(...)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Returns a JSON response back to the frontend.&lt;/p&gt;
&lt;h4 id=&quot;validation&quot;&gt;Validation&lt;/h4&gt;
&lt;p&gt;Before sending emails, we validate user input to prevent unnecessary API calls.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;create-an-email-validation-helper&quot;&gt;Create an Email Validation Helper&lt;/h3&gt;
&lt;p&gt;Create:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;src/lib/helpers.ts
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;export const isValidEmail = (
  email: string
) =&amp;gt;
  /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(
    email
  );
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;why-validate-emails-&quot;&gt;Why Validate Emails?&lt;/h4&gt;
&lt;p&gt;Validation helps:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Improve user experience&lt;/li&gt;
&lt;li&gt;Reduce API usage&lt;/li&gt;
&lt;li&gt;Prevent invalid submissions&lt;/li&gt;
&lt;li&gt;Avoid unnecessary errors&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;why-emails-should-be-sent-server-side&quot;&gt;Why Emails Should Be Sent Server-Side&lt;/h3&gt;
&lt;p&gt;Many beginners try sending emails directly from the frontend.&lt;/p&gt;
&lt;p&gt;This is dangerous because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;API keys become public&lt;/li&gt;
&lt;li&gt;Attackers can abuse your account&lt;/li&gt;
&lt;li&gt;Security risks increase&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Always send emails using:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Route Handlers&lt;/li&gt;
&lt;li&gt;Server Actions&lt;/li&gt;
&lt;li&gt;Backend APIs&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Never expose API keys in client-side code.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;build-a-contact-form&quot;&gt;Build a Contact Form&lt;/h3&gt;
&lt;p&gt;Create:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;src/app/page.tsx
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;&quot;use client&quot;;

import { useActionState } from &quot;react&quot;;
import { isValidEmail } from &quot;@/lib/helpers&quot;;

async function handleSubmit(
  _: unknown,
  formData: FormData
) {
  const email = formData.get(&quot;email&quot;) as string;

  if (!email) {
    return {
      message: &quot;Email is required&quot;,
      success: false,
    };
  }

  if (!isValidEmail(email)) {
    return {
      message: &quot;Please enter a valid email&quot;,
      success: false,
      email,
    };
  }

  const response = await fetch(&quot;/api/send&quot;, {
    method: &quot;POST&quot;,
    body: JSON.stringify({ email }),
    headers: {
      &quot;Content-Type&quot;: &quot;application/json&quot;,
    },
  });

  if (response.ok) {
    return {
      message: &quot;Email sent!&quot;,
      success: true,
    };
  }

  return {
    message: &quot;Something went wrong&quot;,
    success: false,
    email,
  };
}

export default function HomePage() {
  const [state, action, isPending] = useActionState(handleSubmit, { message: '', success: false, email: '' });

  return (
    &amp;lt;main className=&quot;min-h-screen flex flex-col items-center justify-center bg-gray-100 p-4&quot;&amp;gt;
      &amp;lt;h1 className=&quot;text-2xl font-bold mb-4&quot;&amp;gt;Subscribe to our Newsletter&amp;lt;/h1&amp;gt;
      &amp;lt;form action={action}&amp;gt;
        &amp;lt;input defaultValue={state.email} type=&quot;email&quot; name=&quot;email&quot; placeholder=&quot;Enter your email&quot; className=&quot;mb-4 p-2 border rounded w-full&quot; required /&amp;gt;
        &amp;lt;button type=&quot;submit&quot; className=&quot;px-4 py-2 bg-blue-500 text-white rounded w-full cursor-pointer&quot; disabled={isPending}&amp;gt;
          {isPending ? &quot;Sending...&quot; : &quot;Subscribe&quot;}
        &amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
      {state.message &amp;amp;&amp;amp;
        &amp;lt;p className={`mt-4 ${state.success ? 'text-green-500' : 'text-red-500'}`}&amp;gt;{state.message}&amp;lt;/p&amp;gt;
      }
    &amp;lt;/main&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;understanding-useactionstate&quot;&gt;Understanding useActionState&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;useActionState()&lt;/code&gt; helps manage form state automatically.&lt;/p&gt;
&lt;p&gt;It provides:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Current state&lt;/li&gt;
&lt;li&gt;Form action&lt;/li&gt;
&lt;li&gt;Loading state&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Without it, you'd need multiple state variables and manual loading logic.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;test-the-contact-form&quot;&gt;Test the Contact Form&lt;/h3&gt;
&lt;p&gt;Run the application:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Submit an email address.&lt;/p&gt;
&lt;p&gt;Expected flow:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;User enters email&lt;/li&gt;
&lt;li&gt;Email is validated&lt;/li&gt;
&lt;li&gt;API Route executes&lt;/li&gt;
&lt;li&gt;Resend sends email&lt;/li&gt;
&lt;li&gt;User sees success message&lt;/li&gt;
&lt;li&gt;Email arrives in inbox&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h3 id=&quot;using-server-actions-instead-of-api-routes&quot;&gt;Using Server Actions Instead of API Routes&lt;/h3&gt;
&lt;p&gt;Next.js 16 encourages using Server Actions for form submissions.&lt;/p&gt;
&lt;p&gt;Server Actions reduce boilerplate and keep logic closer to components.&lt;/p&gt;
&lt;h3 id=&quot;api-routes-vs-server-actions&quot;&gt;API Routes vs Server Actions&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;API Routes           &lt;/th&gt;&lt;th&gt;Server Actions&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Separate endpoint    &lt;/td&gt;&lt;td&gt;Built into components&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;More boilerplate     &lt;/td&gt;&lt;td&gt;Less boilerplate&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Traditional approach &lt;/td&gt;&lt;td&gt;Modern Next.js&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Great for APIs       &lt;/td&gt;&lt;td&gt;Great for forms&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h3 id=&quot;create-a-server-action&quot;&gt;Create a Server Action&lt;/h3&gt;
&lt;p&gt;Create:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;src/actions/send-email.ts
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;&quot;use server&quot;;

import { resend } from &quot;@/lib/resend&quot;;
import { isValidEmail } from &quot;@/lib/helpers&quot;;

export async function sendEmail(
  _: unknown,
  formData: FormData
) {
  const email = formData.get(&quot;email&quot;) as string;

  if (!email) {
    return {
      message: &quot;Email is required&quot;,
      success: false,
    };
  }

  if (!isValidEmail(email)) {
    return {
      message: &quot;Please enter a valid email&quot;,
      success: false,
      email,
    };
  }

  try {
    await resend.emails.send({
      from: &quot;*Emails are not allowed*&quot;,
      to: email,
      subject: &quot;Hello from Next.js 16&quot;,
      html: &quot;&amp;lt;p&amp;gt;Email sent successfully!&amp;lt;/p&amp;gt;&quot;,
    });

    return {
      message: &quot;Email sent!&quot;,
      success: true,
    };
  } catch {
    return {
      message: &quot;Something went wrong&quot;,
      success: false,
      email,
    };
  }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now update /src/app/page.tsx&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;const [state, action, isPending] = useActionState(handleSubmit, { message: '', success: false, email: '' });
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;to&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;const [state, action, isPending] = useActionState(sendEmail, { message: '', success: false, email: '' });
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now your form can call the Server Action directly without using a separate API route.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;send-beautiful-emails-with-react-email&quot;&gt;Send Beautiful Emails with React Email&lt;/h3&gt;
&lt;p&gt;While plain HTML works, React Email makes creating templates much easier.&lt;/p&gt;
&lt;p&gt;Install the packages:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install react-email @react-email/components
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Benefits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reusable templates&lt;/li&gt;
&lt;li&gt;Type safety&lt;/li&gt;
&lt;li&gt;Responsive layouts&lt;/li&gt;
&lt;li&gt;Better maintainability&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;create-your-first-email-template&quot;&gt;Create Your First Email Template&lt;/h3&gt;
&lt;p&gt;Create:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;src/components/emails/welcome.tsx
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-tsx&quot;&gt;import {
  Html,
  Body,
  Container,
  Heading,
  Text,
  Button,
} from &quot;@react-email/components&quot;;

interface WelcomeEmailProps {
  username: string;
}

export default function WelcomeEmail({
  username,
}: WelcomeEmailProps) {
  return (
    &amp;lt;Html&amp;gt;
      &amp;lt;Body&amp;gt;
        &amp;lt;Container&amp;gt;
          &amp;lt;Heading&amp;gt;
            Welcome!
          &amp;lt;/Heading&amp;gt;

          &amp;lt;Text&amp;gt;
            Hello {username}, thanks for joining our
            platform.
          &amp;lt;/Text&amp;gt;

          &amp;lt;Button href=&quot;https://example.com&quot;&amp;gt;
            Get Started
          &amp;lt;/Button&amp;gt;
        &amp;lt;/Container&amp;gt;
      &amp;lt;/Body&amp;gt;
    &amp;lt;/Html&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;send-dynamic-emails&quot;&gt;Send Dynamic Emails&lt;/h3&gt;
&lt;p&gt;Instead of hardcoding HTML:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;html: &quot;&amp;lt;p&amp;gt;Hello&amp;lt;/p&amp;gt;&quot;;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use React Email templates:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;import WelcomeEmail from &quot;@/components/emails/welcome&quot;;

await resend.emails.send({
  from: &quot;*Emails are not allowed*&quot;,
  to: &quot;*Emails are not allowed*&quot;,
  subject: &quot;Welcome!&quot;,
  react: WelcomeEmail({
    username: &quot;Muhammad&quot;,
  }),
});
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This makes your emails reusable and easier to maintain.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;verify-your-domain-very-important-&quot;&gt;Verify Your Domain (Very Important)&lt;/h3&gt;
&lt;p&gt;For production applications, domain verification is essential.&lt;/p&gt;
&lt;p&gt;Instead of:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;*Emails are not allowed*
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You'll eventually send emails from:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;*Emails are not allowed*
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;why-domain-verification-matters&quot;&gt;Why Domain Verification Matters&lt;/h4&gt;
&lt;p&gt;Verified domains provide:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Better deliverability&lt;/li&gt;
&lt;li&gt;Better branding&lt;/li&gt;
&lt;li&gt;Higher inbox placement&lt;/li&gt;
&lt;li&gt;Reduced spam risk&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;add-a-domain-in-resend&quot;&gt;Add a Domain in Resend&lt;/h3&gt;
&lt;p&gt;Inside the Resend dashboard:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open Domains&lt;/li&gt;
&lt;li&gt;Click Add Domain&lt;/li&gt;
&lt;li&gt;Enter your domain&lt;/li&gt;
&lt;li&gt;Copy the DNS records&lt;/li&gt;
&lt;/ol&gt;
&lt;hr&gt;
&lt;h3 id=&quot;configure-dns-records&quot;&gt;Configure DNS Records&lt;/h3&gt;
&lt;p&gt;Resend typically provides:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SPF&lt;/li&gt;
&lt;li&gt;DKIM&lt;/li&gt;
&lt;li&gt;DMARC&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These records help email providers trust your emails.&lt;/p&gt;
&lt;h4 id=&quot;spf&quot;&gt;SPF&lt;/h4&gt;
&lt;p&gt;Defines which servers can send emails for your domain.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;v=spf1 include:_spf.resend.com ~all
&lt;/code&gt;&lt;/pre&gt;
&lt;h4 id=&quot;dkim&quot;&gt;DKIM&lt;/h4&gt;
&lt;p&gt;Adds a cryptographic signature proving emails are legitimate.&lt;/p&gt;
&lt;h4 id=&quot;dmarc&quot;&gt;DMARC&lt;/h4&gt;
&lt;p&gt;Defines how providers should handle suspicious emails.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-txt&quot;&gt;v=DMARC1; p=none;
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h3 id=&quot;testing-emails-locally&quot;&gt;Testing Emails Locally&lt;/h3&gt;
&lt;p&gt;When testing locally:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use test email addresses&lt;/li&gt;
&lt;li&gt;Monitor API limits&lt;/li&gt;
&lt;li&gt;Verify responses&lt;/li&gt;
&lt;li&gt;Check inbox and spam folders&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Free plans may have sending restrictions.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;common-errors-and-fixes&quot;&gt;Common Errors and Fixes&lt;/h3&gt;
&lt;h4 id=&quot;invalid-api-key&quot;&gt;Invalid API Key&lt;/h4&gt;
&lt;p&gt;Check:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-env&quot;&gt;RESEND_API_KEY=
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Make sure the value is correct.&lt;/p&gt;
&lt;p&gt;Restart the development server after changes.&lt;/p&gt;
&lt;hr&gt;
&lt;h4 id=&quot;domain-not-verified&quot;&gt;Domain Not Verified&lt;/h4&gt;
&lt;p&gt;Symptoms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Emails fail&lt;/li&gt;
&lt;li&gt;Emails land in spam&lt;/li&gt;
&lt;li&gt;Delivery issues&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Solution:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Verify DNS records&lt;/li&gt;
&lt;li&gt;Wait for propagation&lt;/li&gt;
&lt;li&gt;Re-check configuration&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h4 id=&quot;rate-limit-errors&quot;&gt;Rate Limit Errors&lt;/h4&gt;
&lt;p&gt;Free plans have sending limits.&lt;/p&gt;
&lt;p&gt;Avoid:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Infinite loops&lt;/li&gt;
&lt;li&gt;Automated testing spam&lt;/li&gt;
&lt;li&gt;Excessive test emails&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;proper-error-handling&quot;&gt;Proper Error Handling&lt;/h3&gt;
&lt;p&gt;Always wrap email requests in &lt;code&gt;try/catch&lt;/code&gt;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-ts&quot;&gt;try {
  await resend.emails.send();
} catch (error) {
  console.error(error);
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Good error handling makes debugging much easier.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;email-deliverability-best-practices&quot;&gt;Email Deliverability Best Practices&lt;/h3&gt;
&lt;p&gt;To avoid spam folders:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use verified domains&lt;/li&gt;
&lt;li&gt;Avoid ALL CAPS subject lines&lt;/li&gt;
&lt;li&gt;Keep HTML clean&lt;/li&gt;
&lt;li&gt;Use proper sender names&lt;/li&gt;
&lt;li&gt;Include text alternatives&lt;/li&gt;
&lt;li&gt;Avoid excessive links&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;deploy-to-vercel&quot;&gt;Deploy to Vercel&lt;/h3&gt;
&lt;p&gt;Build your application:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Push your code to GitHub and import the repository into Vercel.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;add-environment-variables-in-vercel&quot;&gt;Add Environment Variables in Vercel&lt;/h3&gt;
&lt;p&gt;Inside your Vercel dashboard:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open Project Settings&lt;/li&gt;
&lt;li&gt;Navigate to Environment Variables&lt;/li&gt;
&lt;li&gt;Add:&lt;/li&gt;
&lt;/ol&gt;
&lt;pre&gt;&lt;code class=&quot;language-env&quot;&gt;RESEND_API_KEY
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Redeploy your project after adding environment variables.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;real-world-use-cases&quot;&gt;Real-World Use Cases&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;&lt;th&gt;Use Case       &lt;/th&gt;&lt;th&gt;Example&lt;/th&gt;&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Contact Forms  &lt;/td&gt;&lt;td&gt;Portfolio Websites&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;OTP Emails     &lt;/td&gt;&lt;td&gt;Authentication Systems&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Welcome Emails &lt;/td&gt;&lt;td&gt;SaaS Products&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Password Reset &lt;/td&gt;&lt;td&gt;User Accounts&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Order Receipts &lt;/td&gt;&lt;td&gt;E-commerce Stores&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Notifications  &lt;/td&gt;&lt;td&gt;Dashboards&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Newsletters    &lt;/td&gt;&lt;td&gt;Content Platforms&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;hr&gt;
&lt;h3 id=&quot;common-beginner-mistakes&quot;&gt;Common Beginner Mistakes&lt;/h3&gt;
&lt;h4 id=&quot;sending-emails-from-the-client&quot;&gt;Sending Emails From the Client&lt;/h4&gt;
&lt;p&gt;Never expose API keys publicly.&lt;br&gt;
Always use server-side code.&lt;/p&gt;
&lt;h4 id=&quot;hardcoding-api-keys&quot;&gt;Hardcoding API Keys&lt;/h4&gt;
&lt;p&gt;Use environment variables instead.&lt;/p&gt;
&lt;h4 id=&quot;skipping-validation&quot;&gt;Skipping Validation&lt;/h4&gt;
&lt;p&gt;Always validate user input before sending emails.&lt;/p&gt;
&lt;h4 id=&quot;forgetting-domain-verification&quot;&gt;Forgetting Domain Verification&lt;/h4&gt;
&lt;p&gt;This can significantly hurt email deliverability.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;frequently-asked-questions&quot;&gt;Frequently Asked Questions&lt;/h3&gt;
&lt;h4 id=&quot;is-resend-free-&quot;&gt;Is Resend Free?&lt;/h4&gt;
&lt;p&gt;Yes. Resend offers a free tier suitable for development and small projects.&lt;/p&gt;
&lt;h4 id=&quot;can-i-use-resend-with-next-js-server-actions-&quot;&gt;Can I Use Resend with Next.js Server Actions?&lt;/h4&gt;
&lt;p&gt;Absolutely. Server Actions are one of the best ways to integrate Resend with Next.js 16.&lt;/p&gt;
&lt;h4 id=&quot;do-i-need-a-custom-domain-&quot;&gt;Do I Need a Custom Domain?&lt;/h4&gt;
&lt;p&gt;Not for testing. However, production applications should verify a custom domain.&lt;/p&gt;
&lt;h4 id=&quot;can-i-send-html-emails-&quot;&gt;Can I Send HTML Emails?&lt;/h4&gt;
&lt;p&gt;Yes. You can send raw HTML or use React Email templates.&lt;/p&gt;
&lt;h4 id=&quot;does-resend-work-with-vercel-&quot;&gt;Does Resend Work with Vercel?&lt;/h4&gt;
&lt;p&gt;Yes. Resend integrates perfectly with Vercel deployments.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-s-next-&quot;&gt;What's Next?&lt;/h3&gt;
&lt;p&gt;After learning the basics, explore:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scheduled emails&lt;/li&gt;
&lt;li&gt;Email queues&lt;/li&gt;
&lt;li&gt;Background jobs&lt;/li&gt;
&lt;li&gt;Batch email sending&lt;/li&gt;
&lt;li&gt;Attachments&lt;/li&gt;
&lt;li&gt;Analytics&lt;/li&gt;
&lt;li&gt;Webhooks&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Resend is one of the easiest ways to send transactional emails in Next.js 16.&lt;/p&gt;
&lt;p&gt;Compared to traditional SMTP providers, it offers a significantly better developer experience, simpler setup, and excellent React Email integration.&lt;/p&gt;
&lt;p&gt;In this guide, you learned how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Setup Resend&lt;/li&gt;
&lt;li&gt;Generate API keys&lt;/li&gt;
&lt;li&gt;Send emails using API Routes&lt;/li&gt;
&lt;li&gt;Send emails using Server Actions&lt;/li&gt;
&lt;li&gt;Create React Email templates&lt;/li&gt;
&lt;li&gt;Verify domains&lt;/li&gt;
&lt;li&gt;Deploy to Vercel&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;From here, you can build:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Authentication systems&lt;/li&gt;
&lt;li&gt;SaaS products&lt;/li&gt;
&lt;li&gt;Newsletter platforms&lt;/li&gt;
&lt;li&gt;E-commerce workflows&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h3 id=&quot;helpful-resources&quot;&gt;Helpful Resources&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://nextjs.org/docs/app/getting-started/mutating-data#what-are-server-functions&quot;&gt;Nextjs Server Actions Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://nextjs.org/docs/app/api-reference/file-conventions/route&quot;&gt;Nextjs Route Handlers Docs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&quot;continue-learning&quot;&gt;Continue Learning&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://devstacked.tech/blog/stripe-nextjs-16-guide&quot;&gt;How to Integrate Stripe Checkout with Next.js 16 (2026 Edition)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://devstacked.tech/blog/stripe-payment-element-nextjs-16-guide&quot;&gt;How to Integrate Stripe Payment Element with Next.js 16 (2026 Edition)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://devstacked.tech/blog/stripe-checkout-vs-payment-element&quot;&gt;Stripe Checkout vs Payment Element in 2026: Which One Should You Choose?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;&lt;p&gt;Source Code: &lt;a rel=&quot;nofollow&quot; href=&quot;https://github.com/Muhammad-Ali-sma/Nextjs16_Resend_Email_Setup&quot;&gt;View on Github&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/23215/how-to-setup-resend-email-in-next-js-16-2026-complete-beginner-guide</guid>
<pubDate>Wed, 22 Jul 2026 10:15:22 +0000</pubDate>
</item>
</channel>
</rss>