Prerequisites

Using SDK

1

Install SDK

npm install weesend
2

Initialize SDK

Get the API key from the weeSend dashboard and initialize the SDK
import { WeeSend } from "weesend";

const weesend = new WeeSend("us_12345");
If you are running a self-hosted version of weeSend, pass the base URL as the second argument:
const weesend = new WeeSend("us_12345", "https://app.weesend.com");
3

Send Email

weesend.emails.send({
  to: "hello@acme.com",
  from: "hello@company.com",
  subject: "weeSend email",
  html: "<p>weeSend is the best open source product to send emails</p>",
  text: "weeSend is the best open source product to send emails",
  headers: {
    "X-Campaign": "welcome",
  },
});
Custom headers are forwarded as-is. weeSend only manages the X-Weesend-Email-ID and References headers.

Adding contacts programatically

1

Get the contact book id

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

Add contacts

weesend.contacts
  .create("clzeydgeygff", {
    email: "hey@koushik.dev",
    firstName: "Koushik",
    lastName: "KM",
  })
3

Update contact

weesend.contacts.update("clzeydgeygff", contactId, {
  firstName: "Koushik",
  lastName: "KM",
});