Send your first transactional email from Node.js in 5 minutes
This is the shortest path from npm install to an email your code can rely on. You'll send a test email without touching DNS, then add the three things every real integration needs: error handling, safe retries and a plain-text version. It takes about five minutes, plus the time to verify your domain when you're ready to send for real.
You'll need Node.js 18 or later. The vaartix package works with ESM and CommonJS, and includes TypeScript types.
1. Get an API key (1 minute)
Sign up free at app.vaartix.com with your work email. There's no card and no password: we email you a 6-digit code. Then open API keys and create one. It starts with vx_live_ and is shown only once.
Keep it in an environment variable, never in your code:
export VAARTIX_API_KEY="vx_live_..."
2. Install and send a test email (2 minutes)
npm install vaartix
You don't need a verified domain to try it. Test mode simulates delivery: send from any address at test.vaartix.com to [email protected], and nothing reaches a real inbox or counts towards your limits.
import { Vaartix } from 'vaartix';
const vaartix = new Vaartix(process.env.VAARTIX_API_KEY);
const { data, error } = await vaartix.emails.send({
from: 'Acme <[email protected]>',
to: '[email protected]',
subject: 'Hello from Vaartix',
html: '<strong>It works!</strong>',
});
console.log(data ?? error); // { id: 'em_...' }
Run it and you'll get back an email ID. That's your first email sent. The rest of this post turns it into code you can ship.
3. Handle errors (1 minute)
The SDK never throws for API errors. Every method resolves to { data, error }, and exactly one of them is set. That makes it hard to forget the failure case:
const { data, error } = await vaartix.emails.send(email);
if (error) {
// error.type: 'validation_error', 'rate_limited', 'network_error', ...
// error.statusCode: the HTTP status, or null for network errors
console.error(error.type, error.message);
return;
}
console.log('Sent', data.id);
The ones worth handling on purpose:
validation_error: something in your request is wrong, and the message names the field. Fix the code, don't retry.domain_not_verified: the From address is on a domain that isn't verified for your team yet.rate_limited: more than 10 requests a second. Wait and retry.daily_quota_exceeded: today's sending limit is used up. It resets at midnight IST.network_errororinternal_error: retry, with an idempotency key (next step).
The full list is in Errors.
4. Make retries safe (1 minute)
If a request times out, you can't tell whether the email was accepted. Retry blindly and your customer gets two receipts. An idempotency key fixes that: the same key with the same email within 24 hours returns the first email's ID, and nothing is sent again.
await vaartix.emails.send(email, {
idempotencyKey: `order-${order.id}-receipt`,
});
Base the key on what the email is about, such as order-1042-receipt or user-881-welcome, not on the request. A random key per attempt defeats the purpose. Using the same key for a different email returns idempotency_conflict, because that's almost always a bug. More in Idempotency.
5. Send a text version too
Always send a plain-text version alongside your HTML. Some people read email as text, and it helps keep you out of the spam folder. Pass both in the same call:
await vaartix.emails.send(
{
from: 'Acme <[email protected]>',
to: customer.email,
subject: `Your Acme receipt for order #${order.id}`,
html: receiptHtml,
text: `Thanks for your order #${order.id}. Total: ₹${order.total}.`,
},
{ idempotencyKey: `order-${order.id}-receipt` },
);
If you write your emails as React components with React Email, pass react instead of html, and the SDK renders both the HTML and the text version for you. See the Node.js SDK docs.
6. Check what happened
With a full-access key, you can look up any email by its ID. A test email to [email protected] shows delivered within a second or two:
const { data } = await vaartix.emails.get('em_...');
console.log(data?.status); // 'delivered'
Try [email protected] and [email protected] too, to see how your code handles those outcomes without hurting anyone's reputation. In production, you'll usually want webhooks instead of polling, so your app hears about bounces as they happen.
7. Send real email
When you're ready, verify your domain by publishing the DNS records Vaartix gives you. Then change from to an address on it, such as [email protected], and to to a real person. Nothing else in your code changes.
Until you've verified a domain, a new account can send only to test addresses. New accounts start at 100 emails a day, and the limit grows as you send without bounces or complaints. Limits explains how.
If your first real emails land in spam, our post Why your OTP emails land in spam walks through the fixes.
Already using Nodemailer?
You don't have to rewrite anything. Swap the transport and keep your sendMail() calls:
import nodemailer from 'nodemailer';
import { vaartixTransport } from 'vaartix';
const transporter = nodemailer.createTransport(vaartixTransport()); // reads VAARTIX_API_KEY
Attachments, inline images, cc, bcc and custom headers work as before. There are also guides for Express and Next.js, and a npx vaartix command for sending from the terminal.