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.
- To
- ana@acme.com
- From
- Acme <hello@acme.com>
- Subject
- Reset your password
Reset your password
To ana@acme.com
- Sent09:41:02
- Delivered09:41:03
- Opened09:42:18
Before you send
Create a project
Sign up for free and copy your secret key from the project settings.
Verify your domain
Add the DNS records Plunk shows you. It checks them and tells you when you can send.
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.
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.
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.