Send email
with Next.js

Send from a route handler or server action with fetch. No package to install, and it runs on the Node.js and Edge runtimes.

POST/v1/send
200 OK
To
ana@acme.com
From
Acme <hello@acme.com>
Subject
Reset your password

Reset your password

To ana@acme.com

  1. Sent09:41:02
  2. Delivered09:41:03
  3. Opened09:42:18

Before you send

  1. Create a project

    Sign up for free and copy your secret key from the project settings.

  2. Verify your domain

    Add the DNS records Plunk shows you. It checks them and tells you when you can send.

  3. Send

    Use the API or your framework’s mailer, below. Every email shows up in the dashboard.

Send with the API

Call the send endpoint from a route handler. Keep the secret key on the server: never in a client component.

app/api/welcome/route.ts
export async function POST(request: Request) {
  const {email} = await request.json();

  const response = await fetch('https://send-api.akmarketingseo.com/v1/send', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${process.env.PLUNK_SECRET_KEY}`,
    },
    body: JSON.stringify({
      to: email,
      subject: 'Welcome to Acme',
      body: '<p>Thanks for signing up.</p>',
    }),
  });

  if (!response.ok) {
    return Response.json({error: 'Could not send email'}, {status: 502});
  }

  return Response.json({sent: true});
}

Send with Next.js over SMTP

Already sending with Nodemailer, or using an auth library that takes SMTP settings? Point it at Plunk.

lib/mail.ts
import nodemailer from 'nodemailer';

const transporter = nodemailer.createTransport({
  host: 'smtp.useplunk.com',
  port: 587,
  auth: {user: 'plunk', pass: process.env.PLUNK_SECRET_KEY},
});

await transporter.sendMail({
  from: 'Acme <hello@acme.com>',
  to: 'ana@acme.com',
  subject: 'Welcome to Acme',
  html: '<p>Thanks for signing up.</p>',
});

Frequently asked questions

Send your first email from Next.js.

Start on the free plan with 1,000 emails a month, no credit card needed. When you need more, every email is $0.001, with unlimited contacts and every feature included.