.NET / C# Examples

Validate emails in your .NET applications using the nofakemails API.

Single Email Validation

Validate a single email address with a GET request to the /v1/email/{email} endpoint.

Program.cs
using System.Net.Http.Json;
using System.Text.Json.Serialization;

var client = new HttpClient();
client.BaseAddress = new Uri("https://api.nofakemails.com");
client.DefaultRequestHeaders.Add("X-API-Key", "your-api-key");

var email = "user@example.com";
var response = await client.GetAsync($"/v1/email/{Uri.EscapeDataString(email)}");

response.EnsureSuccessStatusCode();

var result = await response.Content.ReadFromJsonAsync<EmailValidationResult>();
Console.WriteLine(result);

Response class with all fields:

EmailValidationResult.cs
public class EmailValidationResult
{
    [JsonPropertyName("email")]
    public string Email { get; set; } = string.Empty;

    [JsonPropertyName("valid")]
    public bool Valid { get; set; }

    [JsonPropertyName("normalized")]
    public string? Normalized { get; set; }

    [JsonPropertyName("local_part")]
    public string? LocalPart { get; set; }

    [JsonPropertyName("alias")]
    public bool Alias { get; set; }

    [JsonPropertyName("ascii")]
    public bool Ascii { get; set; }

    [JsonPropertyName("role")]
    public string? Role { get; set; }

    [JsonPropertyName("gibberish")]
    public bool Gibberish { get; set; }

    [JsonPropertyName("gibberish_score")]
    public decimal GibberishScore { get; set; }

    [JsonPropertyName("domain")]
    public string? Domain { get; set; }

    [JsonPropertyName("mx")]
    public bool Mx { get; set; }

    [JsonPropertyName("disposable")]
    public bool Disposable { get; set; }

    [JsonPropertyName("public")]
    public bool Public { get; set; }

    [JsonPropertyName("relay")]
    public bool Relay { get; set; }

    [JsonPropertyName("typo")]
    public bool Typo { get; set; }

    [JsonPropertyName("typo_suggestion")]
    public string? TypoSuggestion { get; set; }
}

Response:

{
  "email": "user@example.com",
  "valid": true,
  "normalized": "user@example.com",
  "local_part": "user",
  "alias": false,
  "ascii": true,
  "role": null,
  "gibberish": false,
  "gibberish_score": 0.12,
  "domain": "example.com",
  "mx": true,
  "disposable": false,
  "public": false,
  "relay": false,
  "typo": false,
  "typo_suggestion": null
}

See the Response Format page for a full description of every field.

Batch Validation

Validate up to 64 emails in a single POST request to the /v1/emails endpoint.

Program.cs
using System.Net.Http.Json;
using System.Text.Json.Serialization;

var client = new HttpClient();
client.BaseAddress = new Uri("https://api.nofakemails.com");
client.DefaultRequestHeaders.Add("X-API-Key", "your-api-key");

var emails = new[] { "user1@example.com", "user2@tempmail.com", "user3@gmail.com" };

var response = await client.PostAsJsonAsync("/v1/emails", new { emails });
response.EnsureSuccessStatusCode();

var batch = await response.Content.ReadFromJsonAsync<BatchResponse>();

// Check for partial results (timeout)
if (batch.Partial)
    Console.WriteLine("Warning: some emails may not have been processed");

Console.WriteLine($"Total: {batch.Total}, Valid: {batch.ValidCount}");

foreach (var item in batch.Results)
{
    if (item.Status == "error")
    {
        Console.WriteLine($"{item.Email}: ERROR - {item.Error?.Message}");
        continue;
    }

    Console.WriteLine($"{item.Result!.Email}: Valid={item.Result.Valid}, Disposable={item.Result.Disposable}");
}

Batch response classes:

BatchResponse.cs
public class BatchResponse
{
    [JsonPropertyName("success")]
    public bool Success { get; set; }

    [JsonPropertyName("partial")]
    public bool Partial { get; set; }

    [JsonPropertyName("total")]
    public int Total { get; set; }

    [JsonPropertyName("valid_count")]
    public int ValidCount { get; set; }

    [JsonPropertyName("invalid_count")]
    public int InvalidCount { get; set; }

    [JsonPropertyName("error_count")]
    public int ErrorCount { get; set; }

    [JsonPropertyName("usage_points")]
    public int UsagePoints { get; set; }

    [JsonPropertyName("processing_time_ms")]
    public long ProcessingTimeMs { get; set; }

    [JsonPropertyName("results")]
    public BatchEmailResult[] Results { get; set; } = [];
}

public class BatchEmailResult
{
    [JsonPropertyName("email")]
    public string Email { get; set; } = string.Empty;

    [JsonPropertyName("status")]
    public string Status { get; set; } = string.Empty;

    [JsonPropertyName("result")]
    public EmailValidationResult? Result { get; set; }

    [JsonPropertyName("error")]
    public BatchError? Error { get; set; }
}

public class BatchError
{
    [JsonPropertyName("code")]
    public string Code { get; set; } = string.Empty;

    [JsonPropertyName("message")]
    public string Message { get; set; } = string.Empty;
}

Response:

{
  "success": true,
  "partial": false,
  "total": 3,
  "valid_count": 3,
  "invalid_count": 0,
  "error_count": 0,
  "usage_points": 3,
  "processing_time_ms": 205,
  "results": [
    {
      "email": "user1@example.com",
      "status": "success",
      "result": {
        "email": "user1@example.com",
        "valid": true,
        "normalized": "user1@example.com",
        "local_part": "user1",
        "alias": false,
        "ascii": true,
        "role": null,
        "gibberish": false,
        "gibberish_score": 0.11,
        "domain": "example.com",
        "mx": true,
        "disposable": false,
        "public": false,
        "relay": false,
        "typo": false,
        "typo_suggestion": null
      },
      "error": null
    },
    {
      "email": "user2@tempmail.com",
      "status": "success",
      "result": {
        "email": "user2@tempmail.com",
        "valid": true,
        "normalized": "user2@tempmail.com",
        "local_part": "user2",
        "alias": false,
        "ascii": true,
        "role": null,
        "gibberish": false,
        "gibberish_score": 0.10,
        "domain": "tempmail.com",
        "mx": true,
        "disposable": true,
        "public": false,
        "relay": false,
        "typo": false,
        "typo_suggestion": null
      },
      "error": null
    },
    {
      "email": "user3@gmail.com",
      "status": "success",
      "result": {
        "email": "user3@gmail.com",
        "valid": true,
        "normalized": "user3@gmail.com",
        "local_part": "user3",
        "alias": false,
        "ascii": true,
        "role": null,
        "gibberish": false,
        "gibberish_score": 0.09,
        "domain": "gmail.com",
        "mx": true,
        "disposable": false,
        "public": true,
        "relay": false,
        "typo": false,
        "typo_suggestion": null
      },
      "error": null
    }
  ]
}

Each item in results contains the full validation result. See the Batch Validation response format for details on the envelope fields and per-email result structure.