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

Prerequisites

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

Install

npm install mailrify
yarn add mailrify

Initialize clients

Create one SDK client for your secret key and one for your public key:
import Mailrify from 'mailrify';

const secretClient = new Mailrify(process.env.MAILRIFY_SECRET_KEY as string);
const publicClient = new Mailrify(process.env.MAILRIFY_PUBLIC_KEY as string);
Set the environment variables:
export MAILRIFY_SECRET_KEY="sk_your_secret_key"
export MAILRIFY_PUBLIC_KEY="pk_your_public_key"

Configure base URL and timeout

Use this when testing against staging or local environments:
import Mailrify from 'mailrify';

const client = new Mailrify(process.env.MAILRIFY_SECRET_KEY as string, {
  baseUrl: 'https://api.mailrify.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