Node.js / TypeScript

Official MailSetu SDK for Node.js and TypeScript. Full type safety, async/await API.

Installation

bash
npm install mailsetu
# yarn add mailsetu
# pnpm add mailsetu

Setup

Import the client and initialize it with your API key:

typescript
import MailSetu from 'mailsetu'
// or: const MailSetu = require('mailsetu')

const client = new MailSetu(process.env.MAILSETU_API_KEY!)

Send an email

typescript
const { id, status } = await client.emails.send({
  from: 'Acme <noreply@acme.co>',
  to: ['user@example.com'],
  subject: 'Welcome to Acme!',
  html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
  text: 'Welcome! Thanks for signing up.',  // plain text fallback
})

console.log(id)     // email-xxxxxxxxxxxxxxxx
console.log(status) // 'queued'

Send to multiple recipients

typescript
await client.emails.send({
  from: 'Acme <noreply@acme.co>',
  to: ['alice@example.com', 'bob@example.com'],
  cc: ['manager@acme.co'],
  bcc: ['archive@acme.co'],
  subject: 'Team announcement',
  html: '<p>Big news from the team!</p>',
})

Using templates

First create a template in the dashboard. Then reference it by ID:

typescript
await client.emails.send({
  from: 'Acme <noreply@acme.co>',
  to: ['user@example.com'],
  subject: 'Your order is confirmed',  // overrides template subject
  templateId: 'tmpl_xxxxxxxxxxxxxxxx',
  variables: {
    firstName: 'Rahul',
    orderNumber: '#INV-2847',
    amount: '₹2,499',
  },
})

Send with attachments

typescript
import fs from 'fs'

await client.emails.send({
  from: 'Acme <billing@acme.co>',
  to: ['user@example.com'],
  subject: 'Your invoice',
  html: '<p>Please find your invoice attached.</p>',
  attachments: [
    {
      filename: 'invoice-2847.pdf',
      content: fs.readFileSync('./invoice.pdf').toString('base64'),
      contentType: 'application/pdf',
    },
  ],
})

Batch sending

Send up to 100 emails in a single API call:

typescript
await client.emails.sendBatch([
  {
    from: 'Acme <noreply@acme.co>',
    to: ['alice@example.com'],
    subject: 'Welcome Alice!',
    html: '<p>Hi Alice!</p>',
  },
  {
    from: 'Acme <noreply@acme.co>',
    to: ['bob@example.com'],
    subject: 'Welcome Bob!',
    html: '<p>Hi Bob!</p>',
  },
])

Schedule an email

typescript
await client.emails.send({
  from: 'Acme <noreply@acme.co>',
  to: ['user@example.com'],
  subject: 'Your monthly report',
  html: '<p>Here is your report for this month.</p>',
  scheduledAt: '2026-05-01T09:00:00+05:30',  // IST
})