New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

skymail

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skymail

A robust email service with multiple provider support and automatic failover

latest
npmnpm
Version
0.0.1
Version published
Maintainers
0
Created
Source

Skymail

Node.js CI npm version License: ISC

A robust TypeScript email service package with automatic failover and multiple provider support. Built for reliability and ease of use in modern Node.js applications.

Features

  • Automatic Failover: Seamlessly switch between providers to ensure delivery
  • Multiple Provider Support:
    • SendGrid
    • Mailgun
    • Extensible architecture for custom providers
  • TypeScript First: Full type safety and comprehensive definitions
  • Reliability Features:
    • Priority-based provider selection
    • Automatic retry mechanism
    • Health monitoring
    • Configurable timeouts
  • Developer Experience:
    • Clean, intuitive API
    • Comprehensive error handling
    • Detailed logging options

Installation

npm install skymail

Quick Start

import { EmailService, SendGridProvider, MailgunProvider } from 'skymail';

// Initialize providers
const sendgrid = new SendGridProvider({
  apiKey: 'YOUR_SENDGRID_API_KEY',
  maxRetries: 3,
  retryDelay: 1000
});

const mailgun = new MailgunProvider({
  apiKey: 'YOUR_MAILGUN_API_KEY',
  domain: 'YOUR_DOMAIN',
  maxRetries: 3,
  retryDelay: 1000
});

// Create service with failover
const emailService = new EmailService([
  { provider: sendgrid, priority: 1 },  // Primary
  { provider: mailgun, priority: 2 }    // Backup
]);

// Send email
try {
  const success = await emailService.sendEmail({
    to: 'recipient@example.com',
    from: 'sender@yourdomain.com',
    subject: 'Hello!',
    text: 'Message content',
    html: '<p>Message content</p>'
  });

  console.log('Email sent:', success);
} catch (error) {
  console.error('Failed to send:', error);
}

Architecture

The package follows a modular design with three main components:

  • Email Service: Orchestrates sending process and manages providers
  • Providers: Implement email sending logic for specific services
  • Core Abstractions: Define interfaces and base classes

Architecture Diagram

Provider Configuration

SendGrid

interface SendGridConfig {
  apiKey: string;          // Required
  maxRetries?: number;     // Optional (default: 3)
  retryDelay?: number;     // Optional (default: 1000ms)
}

Mailgun

interface MailgunConfig {
  apiKey: string;         // Required
  domain: string;         // Required
  maxRetries?: number;    // Optional (default: 3)
  retryDelay?: number;    // Optional (default: 1000ms)
}

Email Message Options

interface EmailMessage {
  to: string | string[];
  from: string;
  subject: string;
  text: string;
  html?: string;
  cc?: string | string[];
  bcc?: string | string[];
  replyTo?: string;
  attachments?: Array<{
    filename: string;
    content: Buffer | string;
    contentType?: string;
  }>;
}

Advanced Usage

Custom Provider

import { AbstractEmailProvider, EmailMessage } from 'skymail';

export class CustomProvider extends AbstractEmailProvider {
  constructor(config: YourConfig) {
    super(config);
  }

  protected async sendEmailRequest(message: EmailMessage): Promise<boolean> {
    // Implement provider-specific sending logic
    return true;
  }

  public async isAvailable(): Promise<boolean> {
    // Implement availability check
    return true;
  }
}

Provider Management

// Add new provider
emailService.addProvider(newProvider, 3);

// Remove provider
emailService.removeProvider(existingProvider);

// Update priority
emailService.updatePriority(existingProvider, 2);

// Check status
const status = await emailService.getProvidersStatus();

Error Handling

try {
  const result = await emailService.sendEmail(message);
  if (!result) {
    // All providers failed
  }
} catch (error) {
  if (error instanceof InvalidEmailError) {
    // Handle validation errors
  } else {
    // Handle other errors
  }
}

Contributing

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

License

This project is licensed under the ISC License - see the LICENSE file for details.

Support

Keywords

email

FAQs

Package last updated on 28 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts