// frameworks and platforms
Via APIASP.NET Core email verification with pingutil
EmailAddressAttribute in .NET only checks for a single @ that is not at either end, so ASP.NET Core signup endpoints accept throwaway and non-existent addresses. A typed HttpClient that calls pingutil, used from the signup endpoint, returns a validation problem for disposable or dead addresses and lets everything through when the API cannot answer in time.
Where it connects: ASP.NET Core minimal API endpoint with a typed HttpClient (IHttpClientFactory)
What goes wrong without it
- [EmailAddress] accepts nearly anything, and our trial signups are full of temp-mail accounts.
- Identity sends a confirmation email to every new account and a lot of them bounce.
- We need the check to respect request cancellation and never hang the endpoint.
What you can do with ASP.NET Core and pingutil
ValidationProblem responses
Disposable and invalid addresses return Results.ValidationProblem with an email entry, the same problem-details shape your clients already handle.
Per-call deadlines
Each call links the request CancellationToken with its own budget (2 s for lookups, 5 s for mailbox checks), so an aborted request or a slow mail server never holds the endpoint.
Cached domain categories
IMemoryCache keeps the category per domain for a day, so repeated attempts from the same disposable domain are rejected without a call.
Set it up
- 1
Create an API key in the pingutil dashboard and store it as Pingutil:Key with user secrets locally and an environment variable or key vault in production.
- 2
Register the typed client with AddHttpClient<Pingutil>, setting BaseAddress, the Bearer header and an overall Timeout.
- 3
Configure JsonSerializerOptions with JsonNamingPolicy.SnakeCaseLower so is_spam and did_you_mean bind to your records.
- 4
In the signup endpoint, call LookupAsync, then VerifyAsync, returning a validation problem on spam or invalid results.
- 5
Create the user with the category and a needs-review flag when the status is not valid.
// Program.cs (ASP.NET Core minimal API, .NET 8 or later)
// dotnet user-secrets set "Pingutil:Key" "pk_live_..."
using System.Net;
using System.Text.Json;
using Microsoft.Extensions.Caching.Memory;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMemoryCache();
builder.Services.AddHttpClient<Pingutil>(http =>
{
http.BaseAddress = new Uri("https://pingutil.com/v1/");
http.DefaultRequestHeaders.Authorization = new("Bearer", builder.Configuration["Pingutil:Key"]);
http.Timeout = TimeSpan.FromSeconds(6); // hard ceiling; each call has its own budget below
});
var app = builder.Build();
app.MapPost("/signup", async (SignupRequest req, Pingutil pingutil, IMemoryCache cache, CancellationToken ct) =>
{
var email = req.Email.Trim().ToLowerInvariant();
var at = email.LastIndexOf('@');
if (at < 1 || at == email.Length - 1) return Reject("Enter a valid email address.");
var domain = email[(at + 1)..];
// Cache the domain's category for a day. Never cache the verdict per domain.
if (cache.Get<string>($"pingutil:category:{domain}") == "disposable")
return Reject("Please use a permanent email address.");
var lookup = await pingutil.LookupAsync(email, ct);
if (lookup is not null)
{
cache.Set($"pingutil:category:{lookup.Domain}", lookup.Category, TimeSpan.FromDays(1));
if (lookup.Verdict.IsSpam) return Reject("This email address can't be used. Please use a different one.");
}
var check = await pingutil.VerifyAsync(email, ct);
if (check?.Status == "invalid")
return Reject(check.DidYouMean is { } suggestion ? $"Did you mean {suggestion}?" : "That mailbox does not exist.");
// await users.CreateAsync(email, req.Password, lookup?.Category, needsReview: check?.Status != "valid");
return Results.StatusCode(StatusCodes.Status201Created);
});
app.Run();
static IResult Reject(string message) =>
Results.ValidationProblem(new Dictionary<string, string[]> { ["email"] = [message] });
public record SignupRequest(string Email, string Password);
public record Verdict(bool IsSpam, bool LowTrust, string? Reason);
public record Lookup(string Domain, string Category, Verdict Verdict);
public record Verification(string Status, string Reason, string? DidYouMean);
// Typed client. Returns null when pingutil is slow, down or rate limited: the caller fails open.
public class Pingutil(HttpClient http, ILogger<Pingutil> log)
{
static readonly JsonSerializerOptions Json = new(JsonSerializerDefaults.Web)
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, // is_spam, did_you_mean, skip_enrichment
};
public Task<Lookup?> LookupAsync(string email, CancellationToken ct) =>
CallAsync<Lookup>("lookup", new { input = email, skip_enrichment = true }, TimeSpan.FromSeconds(2), ct);
public Task<Verification?> VerifyAsync(string email, CancellationToken ct) =>
CallAsync<Verification>("verify", new { email }, TimeSpan.FromSeconds(5), ct);
async Task<T?> CallAsync<T>(string path, object body, TimeSpan budget, CancellationToken ct) where T : class
{
using var cts = CancellationTokenSource.CreateLinkedTokenSource(ct);
cts.CancelAfter(budget);
try
{
using var res = await http.PostAsJsonAsync(path, body, Json, cts.Token);
if (res.StatusCode == HttpStatusCode.Unauthorized) log.LogError("pingutil rejected the API key");
return res.IsSuccessStatusCode ? await res.Content.ReadFromJsonAsync<T>(Json, cts.Token) : null;
}
catch (Exception e) when (e is HttpRequestException or OperationCanceledException or JsonException)
{
return null;
}
}
}What to do with each result
| pingutil result | Action in ASP.NET Core |
|---|---|
| verdict.is_spam: true | Return Results.ValidationProblem for the email field. |
| status: invalid with did_you_mean | Return a validation problem that suggests the corrected address. |
| status: risky or unknown | Create the user with EmailConfirmed false and require the confirmation link. |
| null (timeout, 429, network) | Continue the signup and queue the address for a later check. |
Limits to plan for
- IMemoryCache is per instance; across several instances use IDistributedCache or HybridCache with Redis.
- Mailbox checks can take seconds on slow servers and cannot confirm catch-all domains (risky) or silent servers (unknown).
- Per-account defaults: 60 requests a minute, 300 verified addresses and 2,000 lookups a day (3,000 and 30,000 a month); a 429 is treated as unavailable. Those are Free plan limits; Enterprise has custom limits.
ASP.NET Core documentation
- learn.microsoft.com/en-us/aspnet/core/fundamentals/http-requests
- learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis
- learn.microsoft.com/en-us/aspnet/core/performance/caching/memory
ASP.NET Core is a trademark of its owner. This integration uses ASP.NET Core's documented extension points; it is not an official ASP.NET Core app.
Common questions
- Can I use this with MVC controllers and [ApiController]?
- Yes. Inject the typed Pingutil client into the controller, run the same checks in the action and add errors to ModelState, or return ValidationProblem().
- Why set both HttpClient.Timeout and a per-call CancelAfter?
- HttpClient.Timeout is one ceiling for every call through that client. The linked token gives the fast lookup and the slower mailbox check their own budgets and also stops work when the caller disconnects.
Stop bad addresses in ASP.NET Core today
Sign in with your email, create an API key and paste it into the step above. Test on a few real addresses first: the live demo shows exactly what your ASP.NET Core setup will receive.