Skip to main content

Prerequisites

To get the most out of this guide, you’ll need to:

1. Install

npm
npm install sendpost-js-sdk --save

2. Getting Started

JavaScript
const sendpost = require('sendpost-js-sdk');
const emailApi = new sendpost.EmailApi();
const apiKey = 'your_api_key'; // Sub-Account API Key

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>';

const opts = {
  emailMessage: emailMessage
};

emailApi.sendEmail(apiKey, opts)
  .then((data) => {
    console.log('API called successfully. Returned data: ', data);
  })
  .catch((error) => {
    console.error('Error: ', error);
  });

3. Try it for yourself

JavaScript Example

See detailed sdk example