Skip to main content

Prerequisites

To get the most out of this guide, you’ll need to:
You can find your API keys in your SendPost Dashboard. Make sure to use your Sub-Account API Key for sending emails.

1. Install

Install the SendPost JavaScript SDK using npm:
npm
npm install sendpost-js-sdk --save

2. Getting Started

Here’s a simple example to send your first email:
JavaScript
const sendpost = require("sendpost-js-sdk");
const emailApi = new sendpost.EmailApi();
const apiKey = "your_sub_account_api_key"; // Replace with your Sub-Account API Key

// Create email message
const emailMessage = new sendpost.EmailMessage();
emailMessage.from = { email: "[email protected]" };
emailMessage.to = [{ email: "[email protected]" }];
emailMessage.subject = "Hello World";
emailMessage.htmlBody = "<strong>it works!</strong>";

// Send email
const opts = {
  emailMessage: emailMessage,
};

emailApi
  .sendEmail(apiKey, opts)
  .then((data) => {
    console.log("API called successfully. Returned data: ", data);
  })
  .catch((error) => {
    console.error("Error: ", error);
  });
Make sure your sender email domain is verified in your SendPost account before sending emails.

3. Next Steps

Explore more examples and use cases: