JSPM

@euromail/sdk

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 15
  • Score
    100M100P100Q74646F
  • License MIT

Official TypeScript SDK for EuroMail transactional email service

Package Exports

  • @euromail/sdk

Readme

@euromail/sdk

Official TypeScript SDK for the EuroMail transactional email service.

Installation

npm install @euromail/sdk

Quick Start

import { EuroMail } from "@euromail/sdk";

const euromail = new EuroMail({
  apiKey: "em_live_your_api_key_here",
});

// Send an email
const result = await euromail.sendEmail({
  from: "sender@yourdomain.com",
  to: "recipient@example.com",
  subject: "Hello from EuroMail",
  html_body: "<h1>Welcome!</h1><p>Your account is ready.</p>",
});

console.log(`Email queued: ${result.id}`);

Usage

Send email with a template

await euromail.sendEmail({
  from: "noreply@yourdomain.com",
  to: "user@example.com",
  subject: "Welcome",
  template_alias: "welcome-email",
  template_data: {
    name: "John",
    activation_url: "https://example.com/activate/abc123",
  },
});

Send batch emails

const batch = await euromail.sendBatch({
  emails: [
    {
      from: "noreply@yourdomain.com",
      to: "user1@example.com",
      subject: "Hello User 1",
      text_body: "Welcome aboard!",
    },
    {
      from: "noreply@yourdomain.com",
      to: "user2@example.com",
      subject: "Hello User 2",
      text_body: "Welcome aboard!",
    },
  ],
});

Manage domains

// Add and verify a domain
const domain = await euromail.addDomain("yourdomain.com");
console.log("Add these DNS records:", domain.dns_records);

// Check verification status
const verification = await euromail.verifyDomain(domain.id);
if (verification.fully_verified) {
  console.log("Domain is fully verified!");
}

Manage templates

const template = await euromail.createTemplate({
  alias: "welcome-email",
  name: "Welcome Email",
  subject: "Welcome, {{ name }}!",
  html_body: "<h1>Hello {{ name }}</h1><p>Welcome to our service.</p>",
});

Webhooks

await euromail.createWebhook({
  url: "https://yourdomain.com/webhooks/euromail",
  events: ["delivered", "bounced", "complained"],
});

Suppressions

// Manually suppress an address
await euromail.addSuppression("bad-address@example.com", "manual");

// List suppressions
const suppressions = await euromail.listSuppressions({ page: 1, per_page: 50 });

Error Handling

import { EuroMail, AuthenticationError, RateLimitError, ValidationError } from "@euromail/sdk";

try {
  await euromail.sendEmail({ ... });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error("Invalid API key");
  } else if (error instanceof RateLimitError) {
    console.error(`Rate limited. Retry after ${error.retryAfter} seconds`);
  } else if (error instanceof ValidationError) {
    console.error(`Validation error: ${error.message}`);
  }
}

Configuration

const euromail = new EuroMail({
  apiKey: "em_live_...",     // Required
  baseUrl: "https://...",    // Default: https://api.euromail.dev
  timeout: 30000,            // Default: 30000ms
});

Requirements

  • Node.js 18+ (uses native fetch)
  • TypeScript 5.0+ (for type definitions)