Skip to content

Latest commit

 

History

History

api-example

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Keplers.email API Example

This example demonstrates how to send emails using Keplers.email REST API with Node.js and Axios.

Prerequisites

  • Node.js 14 or higher
  • Keplers.email account with API key
  • npm or yarn package manager

Setup

  1. Install dependencies:
npm install
  1. Create .env file from template:
cp .env.example .env
  1. Configure your Keplers.email API credentials in .env:
API_BASE_URL=https://api.keplars.com/api/v1
API_KEY=kms_xxxx
TO_EMAIL=recipient@example.com
USER_NAME=your-username

Usage

Run the example:

npm start

The script will send an instant email and display the results in the console.

Environment Variables

Variable Description Example
API_BASE_URL Keplars API base URL https://api.keplars.com/api/v1
API_KEY Your Keplers.email API key (starts with kms_) kms_xxxx
TO_EMAIL Recipient email address recipient@example.com
USER_NAME Username for personalization your-username

API Endpoint

The example uses the /send-email/instant endpoint which sends emails immediately.

Request Format

{
  "to": ["recipient@example.com"],
  "subject": "Email Subject",
  "body": "<h1>HTML content</h1><p>Email body</p>",
  "is_html": true
}

Request Parameters

Parameter Type Required Description
to array Yes Array of recipient email addresses
subject string Yes Email subject line
body string Yes Email body content (HTML or plain text)
is_html boolean No Set to true for HTML emails, false for plain text

Features

  • Instant email delivery via REST API
  • HTML email support
  • Bearer token authentication
  • Comprehensive error handling with status codes
  • Variable substitution in subject and body

Authentication

The API uses Bearer token authentication. Include your API key in the Authorization header:

Authorization: Bearer kms_xxxx

Error Handling

The example includes comprehensive error handling that displays:

  • HTTP status codes
  • Detailed error response data
  • Network errors

Troubleshooting

  • 401 Unauthorized: Check that your API_KEY is correct and starts with kms_
  • 400 Bad Request: Verify request payload format matches the API specification
  • Network errors: Ensure API_BASE_URL is correct and you have internet connectivity