Send email
with Node.js
Send with the fetch built into Node.js 18 and later, or with Nodemailer over SMTP. Works in Express, Fastify, NestJS and plain scripts.
- 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
One request with the built-in fetch. Use a template ID and data instead of subject and body to keep email copy out of your code.
// Node.js 18+ has fetch built in
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: 'ana@acme.com',
subject: 'Welcome to Acme',
body: '<p>Thanks for signing up.</p>',
}),
});
if (!response.ok) {
throw new Error(`Plunk returned ${response.status}`);
}Send with Node.js over SMTP
If your app already uses Nodemailer, swap the transport settings and keep everything else.
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 Node.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.