@artamail/sdk

JavaScript / Node.js SDK

The core ArtaMail SDK for any JavaScript or Node.js environment.

Installation

Terminal
pnpm add @artamail/sdk

Quick Start

send-email.ts
1import { ArtaMail } from '@artamail/sdk';
2
3const artamail = new ArtaMail({
4 apiKey: process.env.ARTAMAIL_API_KEY
5});
6
7// Send an email
8const result = await artamail.send({
10 template: 'welcome',
11 data: { name: 'John' }
12});
13
14console.log('Email sent:', result.id);
15console.log('Test mode:', result.testMode);

Configuration

typescript
const artamail = new ArtaMail({
// Required
apiKey: 'am_live_sk_xxx',
// Optional
baseUrl: 'https://artamail.artatol.com', // Custom API URL
timeout: 30000, // Request timeout (ms)
retries: 3 // Retry attempts
});
OptionTypeDefaultDescription
apiKeystringYour ArtaMail API key (required)
baseUrlstringhttps://artamail.artatol.comAPI base URL
timeoutnumber30000Request timeout in milliseconds
retriesnumber3Number of retry attempts

Sending Emails

Single Email

typescript
const result = await artamail.send({
template: 'welcome',
data: {
name: 'John',
verifyUrl: 'https://example.com/verify/abc123'
},
// Optional
from: '[email protected]', // Custom sender (must be verified)
fromName: 'My App', // Sender display name
replyTo: '[email protected]', // Reply-to address
priority: 'high', // 'high' | 'normal' | 'low'
});

Batch Emails

Send up to 1000 emails in a single request:

typescript
const result = await artamail.sendBatch({
emails: [
{ to: '[email protected]', template: 'notification', data: { message: 'Hello' } },
{ to: '[email protected]', template: 'notification', data: { message: 'Hello' } }
]
});
// Result: { queued: 2, failed: 0, results: [...], testMode: false }

Get Email Status

typescript
const email = await artamail.getEmail('email-uuid');
console.log(email.status); // queued | sending | sent | delivered | bounced | failed
console.log(email.deliveredAt);
console.log(email.openedAt);

Contacts

typescript
// Create or update contact
await artamail.upsertContact({
name: 'John Doe',
data: { company: 'Acme Inc', plan: 'premium' },
lists: ['newsletter', 'updates']
});
// Get contact
const contact = await artamail.getContact('[email protected]');
// Update contact
await artamail.updateContact('[email protected]', {
name: 'Jane Doe',
data: { plan: 'enterprise' }
});
// Delete contact
await artamail.deleteContact('[email protected]');

Templates

typescript
// List all templates
const templates = await artamail.listTemplates();
for (const template of templates) {
console.log(template.slug, template.name);
console.log('Variables:', template.variables);
}
// Get single template
const template = await artamail.getTemplate('welcome');

Sender Addresses

typescript
const senders = await artamail.listSenderAddresses();
// Find default sender
const defaultSender = senders.find(s => s.isDefault);
// Use custom sender
await artamail.send({
template: 'welcome',
from: senders[0].email,
fromName: senders[0].name
});

Error Handling

typescript
import {
ArtaMailError,
ValidationError,
AuthenticationError,
RateLimitError,
NotFoundError
} from '@artamail/sdk';
try {
await artamail.send({ ... });
} catch (error) {
if (error instanceof ValidationError) {
console.error('Invalid input:', error.details);
} else if (error instanceof AuthenticationError) {
console.error('Invalid API key');
} else if (error instanceof RateLimitError) {
console.error('Rate limited, retry after:', error.retryAfter);
} else if (error instanceof NotFoundError) {
console.error('Resource not found');
}
}
Automatic Retries
The SDK automatically retries failed requests (up to 3 times by default) with exponential backoff for transient errors like network issues or 5xx responses.

TypeScript

The SDK is written in TypeScript and provides full type definitions:

typescript
import type {
ArtaMailConfig,
SendEmailOptions,
SendEmailResult,
BatchEmailOptions,
Contact,
Template,
SenderAddress
} from '@artamail/sdk';