tempmail-blocker
v1.0.1
Published
Block temporary/disposable email domains to prevent spam registrations
Maintainers
Readme
Tempmail Blocker
https://www.npmjs.com/package/tempmail-blocker
A lightweight npm package to block temporary/disposable email domains and prevent spam registrations.
Features
- 4,493+ blocked domains - Comprehensive list of temporary email services
- Zero dependencies - Lightweight and fast
- Works everywhere - Browser, Node.js, React, Vue, Angular, etc.
- TypeScript support - Full type definitions included
- Easy to use - Simple API with multiple validation methods
- Regularly updated - Domain list is actively maintained
Installation
npm install tempmail-blockerUsage
Basic Usage
const { isTempMail } = require('tempmail-blocker');
// Check if an email uses a temporary domain
if (isTempMail('[email protected]')) {
console.log('Temporary email detected!');
}TypeScript
import { isTempMail, validateEmail } from 'tempmail-blocker';
// Check email
const isTemp = isTempMail('[email protected]');
// Validate and throw error if temporary
try {
validateEmail('[email protected]');
} catch (error) {
console.error(error.message); // "Temporary or disposable email addresses are not allowed"
}Express.js Middleware Example
const { isTempMail } = require('tempmail-blocker');
app.post('/register', (req, res) => {
const { email } = req.body;
if (isTempMail(email)) {
return res.status(400).json({
error: 'Temporary email addresses are not allowed'
});
}
// Continue with registration...
});React Form Validation
import { isTempMail } from 'tempmail-blocker';
function RegistrationForm() {
const [error, setError] = useState('');
const handleSubmit = (email) => {
if (isTempMail(email)) {
setError('Please use a permanent email address');
return;
}
setError('');
// Continue with form submission...
};
return (
<form>
<input type="email" onChange={(e) => handleSubmit(e.target.value)} />
{error && <p style={{color: 'red'}}>{error}</p>}
</form>
);
}Browser / Vanilla JavaScript
<script type="module">
import { isTempMail } from './node_modules/tempmail-blocker/dist/index.js';
document.getElementById('emailForm').addEventListener('submit', (e) => {
e.preventDefault();
const email = document.getElementById('email').value;
if (isTempMail(email)) {
alert('Temporary email addresses are not allowed');
return;
}
// Continue with form submission...
});
</script>Vue.js
import { isTempMail } from 'tempmail-blocker';
export default {
data() {
return {
email: '',
error: ''
};
},
methods: {
validateEmail() {
if (isTempMail(this.email)) {
this.error = 'Please use a permanent email address';
return false;
}
this.error = '';
return true;
}
}
};API Reference
isTempMail(email: string): boolean
Check if an email address uses a temporary/disposable email domain.
Parameters:
email(string): The email address to check
Returns:
boolean:trueif the email uses a blocked domain,falseotherwise
Example:
isTempMail('[email protected]'); // true
isTempMail('[email protected]'); // falseisTempMailDomain(domain: string): boolean
Check if a domain is a temporary/disposable email domain.
Parameters:
domain(string): The domain to check
Returns:
boolean:trueif the domain is blocked,falseotherwise
Example:
isTempMailDomain('tempmail.com'); // true
isTempMailDomain('gmail.com'); // falsevalidateEmail(email: string): void
Validate an email address and throw an error if it uses a temporary domain.
Parameters:
email(string): The email address to validate
Throws:
Error: If the email uses a blocked domain
Example:
try {
validateEmail('[email protected]');
} catch (error) {
console.error(error.message);
}isBlocked(domain: string): boolean
Alias for isTempMailDomain(). Check if a domain is blocked.
Parameters:
domain(string): The domain to check
Returns:
boolean:trueif the domain is blocked,falseotherwise
getBlockedDomainsCount(): number
Get the total number of blocked domains.
Returns:
number: The count of blocked domains
Example:
const count = getBlockedDomainsCount();
console.log(`Blocking ${count} domains`); // "Blocking 4493 domains"getBlockedDomains(): string[]
Get all blocked domains as an array.
Returns:
string[]: Array of all blocked domains
Example:
const domains = getBlockedDomains();
console.log(domains); // ['tempmail.com', '10minutemail.com', ...]Use Cases
- User Registration: Prevent users from signing up with temporary emails
- Newsletter Subscriptions: Ensure subscribers use permanent email addresses
- Contact Forms: Block spam from temporary email services
- E-commerce: Validate customer emails during checkout
- API Rate Limiting: Prevent abuse through disposable emails
Blocked Domains
This package blocks over 4,493 temporary email domains including:
- 10minutemail.com
- guerrillamail.com
- tempmail.com
- mailinator.com
- And many more...
Performance
- Fast lookups: Uses a Set for O(1) domain checking
- Lazy loading: Domains are loaded only when first needed
- Memory efficient: Domains are cached in memory after first load
- No external dependencies: Works completely offline
- Browser compatible: No Node.js-specific APIs (fs, path, etc.)
Browser Support
This package works in all modern browsers and environments:
- ✅ Chrome, Firefox, Safari, Edge
- ✅ Node.js (v14+)
- ✅ React, Vue, Angular, Svelte
- ✅ Next.js, Nuxt.js, SvelteKit
- ✅ Webpack, Vite, Rollup, esbuild
- ✅ ES Modules and CommonJS
Contributing
Contributions are welcome! If you find a temporary email domain that should be blocked:
- Fork the repository
- Add the domain to
domains.txt - Submit a pull request
License
MIT
Support
For issues, questions, or suggestions, please open an issue on GitHub.
