Send with your stack
Send emails with Node.js
Send email from Node.js using the mailblastr npm SDK — install once and call mb.emails.send().
The mailblastr npm package is the fastest way to send email from Node.js. Install it once and use the typed SDK — no manual fetch calls or header wrangling required.
This guide sends a single email with mb.emails.send(). Every other SDK method follows the same { data, error } pattern.
Prerequisites
- A verified domain — add one under Domains and publish its SPF/DKIM/DMARC records so your
fromaddress is allowed. (guide) - An API key — create an
mb_key under API Keys; it is shown once at creation. (Authentication) - Node 18 or newer and
npm install mailblastr(oryarn add mailblastr/pnpm add mailblastr).
Send an email
Read the key from process.env.MAILBLASTR_API_KEY. Every SDK call returns { data, error } — check error before using data.
send.mjs
import { MailBlastr } from 'mailblastr';
const mb = new MailBlastr(process.env.MAILBLASTR_API_KEY);
const { data, error } = await mb.emails.send({
from: 'Acme <hello@yourdomain.com>',
to: ['delivered@example.com'],
subject: 'Hello from Node.js',
html: '<p>Sent with the MailBlastr SDK.</p>',
});
if (error) {
throw new Error(error.message);
}
console.log('Sent email', data.id);Handling the response
Every SDK method returns { data, error }. On success data holds the API response ({ id } for a send); on failure error is populated and data is null. Store the returned id to retrieve the email later or to correlate webhook events.
{
"id": "49a3999c-0ce1-4ea6-ab68-afcd6dc2e794"
}Keep your
mb_ API key on the server. Never bundle it into client-side JavaScript or expose it in the browser — anyone with the key can send mail as you. Load it from an environment variable (or your secrets manager), never hard-code it.Next steps
- See the full Send Email API reference for every body parameter (
cc,bcc,reply_to,attachments,tags,scheduled_at). - Explore the SDKs reference for all available methods.
- Calling from a Next.js app? See Send emails with Next.js.