Get started
Node.js quickstart
Send your first email from Node.js, Next.js or Express in about 5 minutes.
NeedsAny accountWorks with a test key on any account. Live keys need a verified phone (Tier 0) for the sandbox, then Tier 1 to send to anyone.
Create an API key
In the dashboard, open API keys and choose Create key. Pick Test to start: test keys never deliver real email. Copy the key now, because it's shown only once, and put it in your server's environment:
PADIMAIL_API_KEY=pm_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxSend an email
import { PadiMail } from "@padimail/node";
const pm = new PadiMail(process.env.PADIMAIL_API_KEY);
const { id } = await pm.emails.send({
from: "Acme Store <onboarding@sandbox.padimail.app>",
to: "delivered@test.padimail.app",
subject: "Hello from PadiMail",
html: "<p>It works.</p>",
});
console.log(`Sent ${id}`);Run it with node --env-file=.env send.mjs. The delivered@test.padimail.app address always reports delivered; see Test mode for addresses that bounce, complain or open.
Check what happened
Open Emails in the dashboard, or ask the API:
const email = await pm.emails.get(id);
console.log(email.status); // "delivered"In a Next.js route handler
import { PadiMail, PadiMailError } from "@padimail/node";
const pm = new PadiMail(process.env.PADIMAIL_API_KEY);
export async function POST(req: Request) {
const { email, name } = await req.json();
try {
const sent = await pm.emails.send({
from: "Acme Store <onboarding@sandbox.padimail.app>",
to: email,
subject: `Welcome, ${name}`,
html: `<p>Thanks for signing up, ${name}.</p>`,
});
return Response.json(sent);
} catch (err) {
if (err instanceof PadiMailError) return Response.json({ code: err.code, message: err.message }, { status: err.status || 502 });
throw err;
}
}In Express
import express from "express";
import { PadiMail } from "@padimail/node";
const pm = new PadiMail(process.env.PADIMAIL_API_KEY);
const app = express();
app.post("/welcome", express.json(), async (req, res) => {
const { id } = await pm.emails.send({
from: "Acme Store <onboarding@sandbox.padimail.app>",
to: req.body.email,
subject: "Welcome to Acme",
text: "Thanks for signing up.",
});
res.json({ id });
});
app.listen(3001);The same call with cURL
curl -X POST https://api.padimail.app/v1/emails \
-H "Authorization: Bearer $PADIMAIL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"from": "Acme Store <onboarding@sandbox.padimail.app>", "to": "delivered@test.padimail.app", "subject": "Hello from PadiMail", "html": "<p>It works.</p>"}'Next steps
- Add your domain so you can send from
you@yourcompany.ng. - Receive webhooks for deliveries, bounces and complaints.
- Send React Email templates.
- Read the Node SDK guide for retries, errors and pagination.
Was this page helpful?