2.0.0 • Published 8 months ago

fast-mailer v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Fast-Mailer

High-performance, intelligent email delivery system powered by advanced technology.

Features

  • 🚀 High-performance email sending with connection pooling
  • 🔒 TLS/SSL security with modern cipher support
  • 🛡️ Advanced rate limiting and spam protection
  • 📊 Detailed metrics and monitoring
  • 📎 Attachment support with MIME type detection
  • ♻️ Comprehensive error handling and retries
  • 📝 Logging with customizable formats and levels
  • 🔷 TypeScript support with full type definitions

What's new in v2.0

  • ✨ Enhanced rate limiting with per-recipient tracking and rapid attempt detection
  • 🔒 Improved security with TLS 1.2/1.3 and modern cipher suites
  • 📊 Extended metrics with detailed failure tracking
  • 🛡️ Advanced spam protection with recipient banning
  • 📝 Enhanced logging with masking of sensitive data
  • ♻️ Improved error handling with detailed error context

FastMailer vs NodeMailer

  • 🚀 Up to 5x faster email sending with connection pooling
  • 🔒 Modern TLS/SSL security with cipher suite control
  • 🛡️ Advanced rate limiting and spam protection
  • 📊 Comprehensive metrics and monitoring
  • 📎 Smart MIME type detection for attachments
  • ♻️ Intelligent error handling and retries
  • 📝 Structured logging with customizable formats
  • 🔷 Full TypeScript support with type definitions

Installation

npm install fast-mailer

Basic Example

import { FastMailer } from 'fast-mailer';

const mailer = new FastMailer({
    host: 'smtp.example.com',
    port: 465,
    secure: true,
    auth: {
        user: 'user@example.com',
        pass: 'password'
    },
    from: 'user@example.com'
});

Sending an Email

mailer.send({
    to: 'recipient@example.com',
    subject: 'Hello, world!',
    text: 'This is a test email.'
});

Sending an Email with Attachments

 mailer.send({
    to: 'recipient@example.com',
    subject: 'Hello, world!',
    text: 'This is a test email.',
    attachments: [{ filename: 'example.txt', path: 'path/to/example.txt' }]
});

Using a Custom Logger

const mailer = new FastMailer({
    host: 'smtp.example.com',
    port: 465,
    secure: true,
    from: 'user@example.com',
    auth: {
        user: 'user@example.com',
        pass: 'password'
    },
    logging: {
        level: 'debug', // 'debug', 'info', 'warn', 'error'
        format: 'json', // 'json' or 'text'
        destination: 'logs/mailer.log',
        customFields: ['messageId', 'recipients'] // Additional fields to include
    }
});

// Logs will be written to logs/mailer.log with entries like:
// JSON format:
{
    "timestamp": "2024-02-20T10:30:45.123Z",
    "level": "info",
    "event": "mail_success", 
    "messageId": "abc123",
    "recipients": ["user@example.com"],
    "subject": "Test Email",
    "sendTime": 150
}

// Text format:
// [2024-02-20T10:30:45.123Z] INFO: {"event":"mail_success","messageId":"abc123",...}

Using Metrics

const mailer = new FastMailer({
    host: 'smtp.example.com',
    port: 465,
    secure: true,
    from: 'user@example.com',
    auth: {
        user: 'user@example.com',
        pass: 'password'
    }
});

// Get current metrics
const metrics = mailer.getMetrics();

console.log('Email Metrics:', {
    total: metrics.emails_total,
    successful: metrics.emails_successful, 
    failed: metrics.emails_failed,
    avgSendTime: metrics.email_send_duration_seconds.avg,
    sendRate: metrics.email_send_rate,
    activeConnections: metrics.active_connections,
    errorsByType: metrics.errors_by_type
});

Rate Limiting

const mailer = new FastMailer({
    host: 'smtp.example.com',
    port: 465,
    secure: true,
    from: 'user@example.com',
    auth: {
        user: 'user@example.com',
        pass: 'password'
    },
    rateLimiting: {
        perRecipient: true,
        burstLimit: 5,
        cooldownPeriod: 1000,
        banDuration: 7200000,
        maxConsecutiveFailures: 3,
        failureCooldown: 300000
    }
});

Configuration Options

OptionTypeDefaultDescription
hoststring-SMTP server hostname (required)
portnumber-SMTP server port (required)
securebooleanfalseWhether to use TLS/SSL connection
authobject-Authentication credentials (required)
auth.userstring-SMTP username
auth.passstring-SMTP password
fromstring-Default sender email address (required)
retryAttemptsnumber3Number of retry attempts for failed sends
timeoutnumber5000Socket timeout in milliseconds
keepAlivebooleanfalseKeep connection alive between sends
poolSizenumber5Maximum number of simultaneous connections
rateLimitingobject-Rate limiting configuration
rateLimiting.perRecipientbooleantrueApply limits per recipient
rateLimiting.burstLimitnumber5Maximum emails per cooldown period
rateLimiting.cooldownPeriodnumber1000Cooldown period in milliseconds
rateLimiting.banDurationnumber7200000Ban duration in milliseconds (2 hours)
rateLimiting.maxConsecutiveFailuresnumber3Max failures before temp ban
rateLimiting.failureCooldownnumber300000Failure cooldown in milliseconds (5 min)
rateLimiting.maxRapidAttemptsnumber5Max rapid attempts before temp ban
rateLimiting.rapidPeriodnumber10000Rapid period in milliseconds (10 seconds)
loggingobject-Logging configuration
logging.levelstring'info'Log level ('debug','info','warn','error')
logging.formatstring'json'Log format ('json' or 'text')
logging.customFieldsstring[][]Additional fields to include in logs
logging.destinationstring-Log file path

License

This project is licensed under the MIT License. See the LICENSE file for details.

2.0.0

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago