Skip to content

Email List Cleaning with API

Bad email addresses hurt your sender reputation, waste money on bounced sends, and can get your domain blacklisted. Before running an email campaign, clean your list. The Apixies Email Inspector API validates each address for format, MX records, disposable providers, and deliverability. You sort them into good, bad, and disposable piles.

The Approach

  1. Read your email list from a CSV file
  2. Call the API for each address
  3. Categorize based on the response: good, bad format, no MX, disposable, role-based
  4. Write results to separate output files
  5. Print a summary

Simple loop. The API does the hard work.

Python Script

This is the complete script. It reads a CSV with an email column, validates each address, and writes four output files.

import csv
import time
import requests

API_KEY = "YOUR_API_KEY"
INPUT_FILE = "emails.csv"
DELAY = 1  # seconds between requests

def validate_email(email):
    response = requests.get(
        "https://apixies.io/api/v1/inspect-email",
        headers={"X-API-Key": API_KEY},
        params={"email": email},
    )
    if response.status_code != 200:
        return {"email": email, "category": "error"}
    return response.json().get("data", {})

def categorize(result):
    if not result.get("format_valid"):
        return "invalid_format"
    if result.get("is_disposable"):
        return "disposable"
    if not result.get("mx_records_found"):
        return "no_mx"
    if result.get("is_role_based"):
        return "role_based"
    return "good"

# Read input
with open(INPUT_FILE, "r") as f:
    reader = csv.DictReader(f)
    emails = [row["email"].strip() for row in reader if row.get("email")]

print(f"Validating {len(emails)} emails...")

# Process
results = {"good": [], "invalid_format": [], "no_mx": [], "disposable": [], "role_based": [], "error": []}

for i, email in enumerate(emails):
    result = validate_email(email)
    category = result.get("category", categorize(result))
    results[category].append(email)

    suggestion = result.get("suggestion")
    status = category
    if suggestion:
        status += f" (did you mean {suggestion}?)"

    print(f"  [{i+1}/{len(emails)}] {email} -> {status}")
    time.sleep(DELAY)

# Write output files
for category, addresses in results.items():
    if addresses:
        filename = f"emails_{category}.csv"
        with open(filename, "w") as f:
            f.write("email\n")
            for addr in addresses:
                f.write(f"{addr}\n")
        print(f"Wrote {len(addresses)} addresses to {filename}")

# Summary
print(f"\nSummary:")
print(f"  Good: {len(results['good'])}")
print(f"  Invalid format: {len(results['invalid_format'])}")
print(f"  No MX records: {len(results['no_mx'])}")
print(f"  Disposable: {len(results['disposable'])}")
print(f"  Role-based: {len(results['role_based'])}")
print(f"  Errors: {len(results['error'])}")

Your input CSV should have an email column:

email
hello@gmail.com
test@mailinator.com
bad-format
nobody@nonexistent-domain-xyz.com
info@stripe.com

Quick Bash Check

If you just need to check a few addresses fast, use a one-liner loop:

while IFS= read -r email; do
  curl -s -H "X-API-Key: YOUR_API_KEY" \
    "https://apixies.io/api/v1/inspect-email?email=$email" | \
    jq -r '"\(.data.email): format=\(.data.format_valid), mx=\(.data.mx_records_found), disposable=\(.data.is_disposable)"'
  sleep 1
done < emails.txt

Output:

hello@gmail.com: format=true, mx=true, disposable=false
test@mailinator.com: format=true, mx=true, disposable=true

Rate Limits and Big Lists

The free tier gives you 75 requests per day. That's enough for small lists. For bigger lists:

  • Add a 1-second delay between requests (the script above does this)
  • Spread validation across multiple days if needed
  • Check the most important addresses first (recent signups, high-value leads)
  • Cache results. An email you checked today doesn't need checking again tomorrow.

Be realistic. If you have 10,000 emails, that's roughly 133 days at 75/day. For large lists, you'd want a paid tier. The free tier works great for ongoing validation of new signups.

Form Validation

Want to catch bad emails before they get into your list? Call the API when the user fills in the email field. Here's a JavaScript example that validates on blur:

const emailInput = document.querySelector('input[type="email"]');
const feedback = document.querySelector('.email-feedback');

emailInput.addEventListener('blur', async () => {
  const email = emailInput.value.trim();
  if (!email) return;

  feedback.textContent = 'Checking...';

  const response = await fetch(
    `https://apixies.io/api/v1/inspect-email?email=${encodeURIComponent(email)}`,
    { headers: { "X-API-Key": "YOUR_API_KEY" } }
  );

  const { data } = await response.json();

  if (!data.format_valid) {
    feedback.textContent = 'Invalid email format';
  } else if (data.is_disposable) {
    feedback.textContent = 'Disposable emails are not allowed';
  } else if (data.suggestion) {
    feedback.textContent = `Did you mean ${data.suggestion}?`;
  } else if (!data.mx_records_found) {
    feedback.textContent = 'This domain doesn\'t accept email';
  } else {
    feedback.textContent = '';
  }
});

This catches typos, disposable addresses, and dead domains in real time. Users get instant feedback.

What to Do With Results

Once you've cleaned your list:

  • Good emails: safe to send to
  • Invalid format: delete them, they can't receive mail
  • No MX records: the domain doesn't have mail servers, remove them
  • Disposable: your call. Some businesses block these outright, others keep them for low-priority communication
  • Role-based (info@, admin@): keep them but expect lower engagement rates

Next Steps

Try the Email Inspector API

Free tier is for development & small projects. 75 requests/day with a registered account.

Getting Started

Explore

Resources

Get Started Free

Free for development and small projects.

Get Free API Key

We use cookies for analytics to understand how our site is used. Privacy Policy