> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sendpost.io/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript SDK Quickstart

> Learn how to configure and send your first email with SendPost JavaScript SDK

## Prerequisites

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

* [**Create a SendPost Account**](https://app.sendpost.io/register)
* [**Install Node.js**](https://nodejs.org/en/download) (v14 or higher)
* A **Sub-Account API Key** from your SendPost dashboard

<Info>
  You can find your API keys in your [SendPost
  Dashboard](https://app.sendpost.io). Make sure to use your Sub-Account API Key
  for sending emails.
</Info>

## 1. Install

Install the SendPost JavaScript SDK using npm:

```shellscript npm theme={null}
npm install sendpost-js-sdk --save
```

## 2. Getting Started

Here's a simple example to send your first email:

```javascript JavaScript theme={null}
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: "richard@piedpiper.com" };
emailMessage.to = [{ email: "gavin@hooli.com" }];
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);
  });
```

<Warning>
  Make sure your sender email domain is verified in your SendPost account before
  sending emails.
</Warning>

## 3. Next Steps

Explore more examples and use cases:

<Columns cols={3}>
  <Card title="JavaScript SDK" icon="npm" href="https://www.npmjs.com/package/sendpost-js-sdk">
    View the official SDK package on npm
  </Card>

  <Card title="SDK Examples" icon="github" href="https://github.com/sendpost/sendpost-examples-js">
    Comprehensive email sending examples including CC, BCC, and attachments
  </Card>

  <Card title="ESP Workflow Example" icon="diagram-project" href="https://github.com/sendpost/js-esp-example">
    Full-featured example app with comprehensive ESP workflow
  </Card>
</Columns>
