Skip to main content

Prerequisites

Using SDK

This example is based on the Mailrify’s official mailrify-node SDK library.
1

Install SDK

npm install mailrify
2

Initialize SDK

Get the API key from the Mailrify dashboard and initialize the SDK.
import { Client } from 'mailrify';

const mailrify = new Client({ 
    apiKey: 'YOUR_API_KEY'
});
3

Send Email

const sendEmail = async () => {
  const response = await mailrify.emails.send({
    from: 'Your app <[email protected]>',
    to: '[email protected]',
    subject: 'Welcome to Mailrify 🚀',
    html: '<p>It works! 👋</p>',
    text: 'It works!',
    headers: {
      "X-Campaign": "welcome",
    }
  });

  console.log('Mailrify email queued:', response);
};

sendEmail().catch((error) => {
  console.error('Failed to send email with Mailrify:', error);
});
Custom headers are forwarded as-is. Mailrify only manages the X-Usesend-Email-ID and References headers.

Adding contacts programatically

1

Get the contact book id

Get the contact book id from the Mailrify dashboard. Copy the contact book id.
2

Add contacts

mailrify.contacts
  .create(contactBookId, {
    email: "[email protected]",
    firstName: "John",
    lastName: "Doe",
  })
3

Update contact

mailrify.contacts.update(contactBookId, contactId, {
  firstName: "John",
  lastName: "Doe",
});