All frameworks

Send Email from Next.js

Send email from Next.js using Server Actions and API routes

1

Install the SDK

npm install sendpigeon
2

Set your API key

SENDPIGEON_API_KEY=your_api_key_here

Get your API key from the dashboard.

3

Send your first email

typescript
// app/actions/contact.ts
"use server";

import { SendPigeon } from "sendpigeon";

const pigeon = new SendPigeon(process.env.SENDPIGEON_API_KEY!);

export async function sendContactEmail(formData: FormData) {
  const email = formData.get("email") as string;
  const name = formData.get("name") as string;

  const { data, error } = await pigeon.send({
    from: "hello@yourdomain.com",
    to: email,
    subject: `Thanks for reaching out, ${name}!`,
    html: `<h1>We got your message</h1><p>We'll get back to you soon.</p>`,
  });

  if (error) {
    return { success: false, error: error.message };
  }

  return { success: true, emailId: data.id };
}

Why use SendPigeon with Next.js?

  • Works with Server Actions and API routes
  • Compatible with Node.js and Edge Runtime
  • Deploy to Vercel, Netlify, or any host
  • 99.9% deliverability with dedicated IPs
  • Real-time analytics and webhook events
🧪

Testing locally? Use our local email server to catch emails without sending real ones.

🎨

Prefer visual editing? Build email templates with our free drag-and-drop builder. Learn more →

Ready to send emails from Next.js?

Start free with 3,000 emails/month. No credit card required.

Get Started Free

Other JavaScript frameworks