EmailFilter

Code examples

Each example sends an address to POST /filter-email and accepts it when the verdict is accepted. Replace the URL and key with yours, and decide what to do when EmailFilter cannot be reached: these examples let the address through, so an outage never blocks sign-ups.

Shell

curl -s -X POST http://localhost:8000/filter-email \
  -H "Content-Type: application/json" \
  -H "X-API-Key: $EMAILFILTER_API_KEY" \
  -d '{"email": "test@mailinator.com"}' | jq -r .verdict

PHP

function email_allowed(string $email): bool {
    $ch = curl_init('http://localhost:8000/filter-email');
    curl_setopt_array($ch, [
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 15,
        CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-API-Key: ' . getenv('EMAILFILTER_API_KEY')],
        CURLOPT_POSTFIELDS => json_encode(['email' => $email]),
    ]);
    $body = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    curl_close($ch);
    if ($status === 422) return false;                  // not a valid address
    if ($status !== 200 || $body === false) return true; // EmailFilter unreachable
    return json_decode($body, true)['verdict'] === 'accepted';
}

Python

import os
import requests

def email_allowed(email: str) -> bool:
    try:
        r = requests.post(
            "http://localhost:8000/filter-email",
            json={"email": email},
            headers={"X-API-Key": os.environ.get("EMAILFILTER_API_KEY", "")},
            timeout=15,
        )
    except requests.RequestException:
        return True  # EmailFilter unreachable
    if r.status_code == 422:
        return False  # not a valid address
    return r.ok and r.json()["verdict"] == "accepted"

JavaScript (Node.js)

export async function emailAllowed(email) {
  try {
    const r = await fetch('http://localhost:8000/filter-email', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json', 'X-API-Key': process.env.EMAILFILTER_API_KEY ?? '' },
      body: JSON.stringify({ email }),
      signal: AbortSignal.timeout(15000),
    });
    if (r.status === 422) return false; // not a valid address
    if (!r.ok) return true;
    return (await r.json()).verdict === 'accepted';
  } catch {
    return true; // EmailFilter unreachable
  }
}

Call it from your server, never from the browser: the API key must stay secret.

Go

func EmailAllowed(ctx context.Context, email string) bool {
	body, _ := json.Marshal(map[string]string{"email": email})
	req, _ := http.NewRequestWithContext(ctx, http.MethodPost, "http://localhost:8000/filter-email", bytes.NewReader(body))
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("X-API-Key", os.Getenv("EMAILFILTER_API_KEY"))
	resp, err := (&http.Client{Timeout: 15 * time.Second}).Do(req)
	if err != nil {
		return true // EmailFilter unreachable
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusUnprocessableEntity {
		return false // not a valid address
	}
	var out struct{ Verdict string }
	if resp.StatusCode != http.StatusOK || json.NewDecoder(resp.Body).Decode(&out) != nil {
		return true
	}
	return out.Verdict == "accepted"
}

Using the score yourself

The verdict uses EMAILFILTER_ACCEPT_SCORE (60). You can also read score and the individual fields and make your own rules, for example asking for email confirmation when the score is between 40 and 60 instead of rejecting. When the answer has a skipped field, the verdict was already certain and the score counts only the checks that ran; treat such addresses as rejected. See API reference for every field.

Edit this page on GitHub

Keep fake addresses out before they sign up.

Free and open source. No sign-up, no API key, no address leaves your server.

10test@mailinator.comrejectedDisposable email domain 30xkcdqwrt@nonexistent.examplerejectedNo mail servers 90john.smith@gmail.comacceptedMailbox exists, established domain