How Abstract API Handles Email Validation in ASP.NET
Abstract API addresses the core weaknesses of traditional validation methods. It replaces brittle syntax checks with a real-world deliverability assessment through a single API call.
- A single REST call returns a clear deliverability status. This allows you to build logic based on real-world sendability, not just syntax.
- It performs real-time MX and SMTP checks, plus detects catch-all, disposable, and role-based addresses. This removes the need for custom DNS or SMTP code and reduces false positives.
- The API automatically suggests corrections for common typos, like 'gmial' to 'gmail'. This helps salvage valid user signups without extra steps.
- As a SaaS solution, all rule updates, new TLDs, and system improvements deploy automatically. This eliminates maintenance overhead for your team.
How to Bring Abstract API to Your Dev Environment
Once you understand Abstract’s capabilities, you can add its email validation API to your project with ease. The process requires just a few configuration steps to connect your application to the service.
- Create a free account on Abstract, enable the Email Verification & Validation API, and copy your API key.
- Add the Abstract API endpoint to your application's configuration file.
- In your Program.cs or Startup file, register HttpClient for dependency injection.
- Define Plain Old CLR Objects (POCOs) that match the structure of the API's JSON response.
- Implement a validator class that sends a GET request to the API endpoint and deserializes the response.
- Invoke the validator from your controller or service layer to check email deliverability.
public record Meta(bool value, string text);
public class AbstractEmailResponse
{
public string email { get; init; }
public string autocorrect { get; init; }
public string deliverability { get; init; }
public float quality_score { get; init; }
public Meta is_valid_format { get; init; }
public Meta is_free_email { get; init; }
public Meta is_disposable_email { get; init; }
public Meta is_role_email { get; init; }
public Meta is_catchall_email { get;init; }
public Meta is_mx_found { get; init; }
public Meta is_smtp_valid { get; init; }
}
Sample Email Validation Implementation with Abstract API
The C# code below demonstrates a call to the Abstract API endpoint. It constructs a request URL with your API key and the email address you want to validate. The code then awaits the JSON response and deserializes it into the AbstractEmailResponse object. The final line returns a boolean value based on whether the email's deliverability status is "DELIVERABLE" and the SMTP check is valid, which confirms the mail server will accept the email.
var http = _clientFactory.CreateClient();
var uri = $"{_cfg.Endpoint}?api_key={_cfg.ApiKey}&email={email}";
var result = await http.GetFromJsonAsync<AbstractEmailResponse>(uri);
return result.deliverability == "DELIVERABLE" && result.is_smtp_valid.value;
Here is a representative response from the API for a valid address. The key fields are deliverability, which classifies the address as DELIVERABLE, UNDELIVERABLE, RISKY, or UNKNOWN, and quality_score, a numeric representation of confidence. The boolean flags for disposable, role-based, and catch-all domains allow you to enforce custom business rules.
{
"email": "johnsmith@gmail.com",
"autocorrect": "",
"deliverability": "DELIVERABLE",
"quality_score": 0.9,
"is_valid_format": { "value": true, "text": "TRUE" },
"is_free_email": { "value": true, "text": "TRUE" },
"is_disposable_email":{ "value": false, "text": "FALSE" },
"is_role_email": { "value": false, "text": "FALSE" },
"is_catchall_email": { "value": false, "text": "FALSE" },
"is_mx_found": { "value": true, "text": "TRUE" },
"is_smtp_valid": { "value": true, "text": "TRUE" }
}
Final Thoughts
Traditional validation methods often fail because they only check syntax, not deliverability. This leads to bounced emails and lost users. Abstract API provides a robust alternative. It performs real-time checks to confirm an email address can actually receive mail.
To reliably validate user emails, consider creation of an account on Abstract API and get your free API key.