When building real-world web applications, validating an email address is not just about format (@ and .).
A common problem is users signing up with disposable or temporary email providers like mailinator.com, tempmail.com, etc.
In this blog, I’ll walk through a simple, efficient, and production-ready approach to block disposable email domains in an ASP.NET Core application using:
IMemoryCache
A JSON-based domain list
Clean service-based design
Disposable email addresses are often used for:
Spam registrations
Free-trial abuse
Fake accounts
Bot signups
Blocking them early improves:
Data quality
Security
Email deliverability
User authenticity
The idea is simple:
Maintain a list of blocked domains in a JSON file
Load the domains into memory at application startup
Cache them using IMemoryCache
Validate the email domain during registration or form submission
This approach is:
⚡ Fast (in-memory lookup)
🔄 Reloadable
📦 Dependency-injection friendly
🚫 No external APIs required
Note: I am using json file, but we can use database, txt file, and etc
Example domains.json:
[
"mailinator.com",
"tempmail.com",
"10minutemail.com"
]
You can find the complete service implementation here:
👉 https://github.com/ravinder25886/RS.Utilities/tree/main/Validation/Service
The domains.json file is available at:
👉 https://github.com/ravinder25886/RS.Utilities/tree/main/Data
You have two ways to use this solution:
Clone the full RS.Utilities project
This repository includes multiple reusable helper and utility classes that can significantly reduce development time.
👉 https://github.com/ravinder25886/RS.Utilities/tree/main
Use only what you need
If you prefer a lightweight approach, simply copy:
The Validation/Service folder
The domains.json file
and integrate them directly into your project.
Both options work seamlessly—choose the one that best fits your project structure and requirements.
Keeping domains in a JSON file makes it:
Easy to update
Source-control friendly
Environment-independent
Domains are loaded once
No file reads on every request
Sliding expiration keeps memory usage optimized
Register the service in Program.cs:
builder.Services.AddMemoryCache();
builder.Services.AddSingleton<IDisposableEmailService, DisposableEmailService>();
if (_disposableEmailService.IsDisposable(model.Email))
{
ModelState.AddModelError(
"Email",
"Disposable email addresses are not allowed."
);
}
Perfect for:
Registration forms
Contact forms
Trial signups
If you update domains.json, simply call:
No app restart required 🚀
✅ No third-party API
✅ No recurring cost
✅ High performance
✅ Easy to maintain
✅ Production-ready
Periodic background refresh (IHostedService)
Admin UI to manage blocked domains
Wildcard or subdomain support
Logging & monitoring
Combine with regex + MX validation
Blocking disposable email addresses is a small feature with a big impact.
This lightweight, cache-driven approach fits perfectly into modern ASP.NET Core applications and gives you full control without external dependencies.
If you’re building authentication, onboarding, or SaaS platforms—this utility is a must-have.
Thanks, for reading the blog, I hope it helps you. Please share this link on your social media accounts so that others can read our valuable content. Share your queries with our expert team and get Free Expert Advice for Your Business today.
Hire me on Linkedin
My portfolio