> From npm install to a test email, then the parts real code needs: error handling, safe retries with idempotency keys and a plain-text version.

Source: https://vaartix.com/blog/send-email-nodejs

[Blog](https://vaartix.com/blog)

# Send your first transactional email from Node.js in 5 minutes

20 November 2026 · 5 min read · Vaartix team

-   [Developers](https://vaartix.com/blog/tag/developers)

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](https://app.vaartix.com/?signup) 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 `delivered@test.vaartix.com`, 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 <onboarding@test.vaartix.com>',
  to: 'delivered@test.vaartix.com',
  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_error`** or **`internal_error`**: retry, with an idempotency key (next step).

The full list is in [Errors](https://vaartix.com/docs/concepts/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](https://vaartix.com/docs/sending/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 <orders@acme.in>',
    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](https://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](https://vaartix.com/docs/sdks/node/#react-email).

## 6\. Check what happened

With a full-access key, you can look up any email by its ID. A test email to `delivered@test.vaartix.com` shows `delivered` within a second or two:

```
const { data } = await vaartix.emails.get('em_...');
console.log(data?.status); // 'delivered'
```

Try `bounced@test.vaartix.com` and `complained@test.vaartix.com` too, to see how your code handles those outcomes without hurting anyone's reputation. In production, you'll usually want [webhooks](https://vaartix.com/docs/webhooks/setup/) instead of polling, so your app hears about bounces as they happen.

## 7\. Send real email

When you're ready, [verify your domain](https://vaartix.com/docs/domains/verify/) by publishing the DNS records Vaartix gives you. Then change `from` to an address on it, such as `orders@acme.in`, 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](https://vaartix.com/docs/concepts/limits/#daily-limit) explains how.

If your first real emails land in spam, our post [Why your OTP emails land in spam](https://vaartix.com/blog/otp-emails-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](https://vaartix.com/docs/guides/express/) and [Next.js](https://vaartix.com/docs/guides/nextjs/), and a `npx vaartix` command for sending from the terminal.

## Related posts

-   [Sending OTPs: delays, retries and what users actually see](https://vaartix.com/blog/otp-email-delays) 30 November 2026
-   [Send email from your AI assistant with the Vaartix MCP server](https://vaartix.com/blog/connect-ai-assistant-mcp) 29 November 2026
-   [Verify webhook signatures in Node, Python and PHP](https://vaartix.com/blog/verify-webhook-signatures) 28 November 2026

**Vaartix is a transactional email API built in India.** It sends through Amazon SES in Mumbai, keeps your data in India and is priced in rupees. Anyone can sign up free, and the Free plan has every feature.

[Sign up free](https://app.vaartix.com/?signup)
