opensourceprojects.dev

A broadsheet for software that doesn't ask for your email

Block throwaway emails smartly.
GitHub RepoImpressions41

Project Description

View on GitHub

Block Throwaway Emails Like a Pro with disposable-email-validator

Fake signups from disposable email addresses? We’ve all been there. Whether it’s spam accounts, fraudulent users, or just lazy testers bypassing your staging environment, throwaway emails can pollute your database and skew analytics.

Enter disposable-email-validator—a configurable, type-safe library to block disposable domains and plus-addressed emails (like [email protected]) with environment-specific rules.


What It Does

This npm package:
✔ Blocks thousands of known disposable domains (e.g., 10minutemail.com) using a built-in list.
✔ Optionally blocks plus addressing (e.g., [email protected]).
✔ Supports custom rules per environment—strict in production, lenient in development.
✔ Allows allowlisting trusted domains or emails.


Why It’s Cool

  • Environment-aware: Configure different rules for production vs. development (or any custom env name).
  • Extendable: Merge with or override the built-in disposable domain list.
  • TypeScript-first: Fully typed for better DX.
  • Lightweight: Zero dependencies, just business logic.

Perfect for:

  • SaaS signup flows
  • Reducing fake accounts in production
  • Letting testers use disposable emails in dev/staging

How to Use It

  1. Install:
    npm install disposable-email-validator
    
  2. Configure:
    import { DisposableEmailValidator } from 'disposable-email-validator';
    
    const config = {
      production: {
        rules: {
          allow_disposable_emails: false, // Block throwaways
          allow_plus_addressing: false,    // Block user+tag@
        },
        trustedDomains: ['mycompany.com'], // Always allow these
      },
      development: {
        rules: {
          allow_disposable_emails: true,   // Allow throwaways for testing
        },
      },
    };
    
    const validator = new DisposableEmailValidator('production', config);
    const result = validator.validateEmail('[email protected]');
    console.log(result); // { success: false, error: 'Disposable email addresses are not allowed' }
    

Final Thoughts

This library nails the balance between strictness and flexibility. You get production-grade blocking without sacrificing developer convenience.

If you’ve ever manually maintained a denylist or fought spam signups, give it a spin. And if you’re feeling generous, drop a ⭐ on GitHub to support the creator!

Bonus: The default domain list is sourced from disposable-email-domains, so it’s always up-to-date.


🔗 Resources:

Found this useful? Let me know on Twitter [@yourhandle]. 🚀

GitHub Repository:

Back to Projects
Project ID: 1941535108076536096Last updated: July 5, 2025 at 06:30 PM