This example demonstrates how to send emails using Keplers.email REST API with Node.js and Axios.
- Node.js 14 or higher
- Keplers.email account with API key
- npm or yarn package manager
- Install dependencies:
npm install- Create
.envfile from template:
cp .env.example .env- 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-usernameRun the example:
npm startThe script will send an instant email and display the results in the console.
| 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 |
The example uses the /send-email/instant endpoint which sends emails immediately.
{
"to": ["recipient@example.com"],
"subject": "Email Subject",
"body": "<h1>HTML content</h1><p>Email body</p>",
"is_html": true
}| 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 |
- Instant email delivery via REST API
- HTML email support
- Bearer token authentication
- Comprehensive error handling with status codes
- Variable substitution in subject and body
The API uses Bearer token authentication. Include your API key in the Authorization header:
Authorization: Bearer kms_xxxx
The example includes comprehensive error handling that displays:
- HTTP status codes
- Detailed error response data
- Network errors
- 401 Unauthorized: Check that your
API_KEYis correct and starts withkms_ - 400 Bad Request: Verify request payload format matches the API specification
- Network errors: Ensure
API_BASE_URLis correct and you have internet connectivity