@artamail/sdk
JavaScript / Node.js SDK
The core ArtaMail SDK for any JavaScript or Node.js environment.
Installation
Terminal
pnpm add @artamail/sdkQuick Start
send-email.ts
1import { ArtaMail } from '@artamail/sdk';23const artamail = new ArtaMail({4 apiKey: process.env.ARTAMAIL_API_KEY5});67// Send an email8const result = await artamail.send({9 to: '[email protected]',10 template: 'welcome',11 data: { name: 'John' }12});1314console.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});| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | — | Your ArtaMail API key (required) |
baseUrl | string | https://artamail.artatol.com | API base URL |
timeout | number | 30000 | Request timeout in milliseconds |
retries | number | 3 | Number of retry attempts |
Sending Emails
Single Email
typescript
const result = await artamail.send({ to: '[email protected]', 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 | failedconsole.log(email.deliveredAt);console.log(email.openedAt);Contacts
typescript
// Create or update contactawait artamail.upsertContact({ email: '[email protected]', name: 'John Doe', data: { company: 'Acme Inc', plan: 'premium' }, lists: ['newsletter', 'updates']});// Get contactconst contact = await artamail.getContact('[email protected]');// Update contactawait artamail.updateContact('[email protected]', { name: 'Jane Doe', data: { plan: 'enterprise' }});// Delete contactawait artamail.deleteContact('[email protected]');Templates
typescript
// List all templatesconst templates = await artamail.listTemplates();for (const template of templates) { console.log(template.slug, template.name); console.log('Variables:', template.variables);}// Get single templateconst template = await artamail.getTemplate('welcome');Sender Addresses
typescript
const senders = await artamail.listSenderAddresses();// Find default senderconst defaultSender = senders.find(s => s.isDefault);// Use custom senderawait artamail.send({ to: '[email protected]', 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';