Skip to main content
Use the official Node.js SDK to call the MailGlyph API from server-side apps.

Prerequisites

Before you start, make sure you have:
  • A MailGlyph secret API key (sk_...) for server-side API requests
  • A MailGlyph public API key (pk_...) for event tracking (/v1/track)
  • At least one verified sending domain for email sending
Setup links:

Install

npm install mailglyph
yarn add mailglyph

Initialize clients

Create one SDK client for your secret key and one for your public key:
import MailGlyph from 'mailglyph';

const secretClient = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string);
const publicClient = new MailGlyph(process.env.MAILGLYPH_PUBLIC_KEY as string);
Set the environment variables:
export MAILGLYPH_SECRET_KEY="sk_your_secret_key"
export MAILGLYPH_PUBLIC_KEY="pk_your_public_key"

Configure base URL and timeout

Use this when testing against staging or local environments:
import MailGlyph from 'mailglyph';

const client = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string, {
  baseUrl: 'https://api.mailglyph.com',
  timeout: 30_000
});

Check key type at runtime

The SDK exposes keyType so you can enforce usage in your app:
if (secretClient.keyType !== 'secret') {
  throw new Error('Expected a secret key client.');
}

if (publicClient.keyType !== 'public') {
  throw new Error('Expected a public key client.');
}

Next pages