NewConnect Claude, Cursor, ChatGPT, and other AI agents to API Ninjas via our MCP server

How to Validate an Email Address in Python

Validate Email APIUpdated May 23, 2026
To validate an email address in Python, send a GET request to the API Ninjas Validate Email endpoint and inspect the is_valid, mx_found, and is_disposable flags in the response:
email_check.py
import requests

API_KEY = 'YOUR_API_KEY'
response = requests.get(
    'https://api.api-ninjas.com/v1/validateemail',
    params={'email': 'test@example.com'},
    headers={'X-Api-Key': API_KEY},
)
print(response.json())

Prerequisites

Step 1: Get your API key

Sign up at api-ninjas.com/register.

Step 2: Make the API request

email_check.py
import requests

API_KEY = 'YOUR_API_KEY'
response = requests.get(
    'https://api.api-ninjas.com/v1/validateemail',
    params={'email': 'test@example.com'},
    headers={'X-Api-Key': API_KEY},
)
print(response.json())

Step 3: Inspect the response

JSON
{
  "email": "test@example.com",
  "is_valid": true,
  "is_disposable": false,
  "mx_found": true,
  "smtp_check": true
}

Complete example with deliverability filter

A real validation flow rejects three things: bad syntax, domains without mail servers, and disposable addresses:

email_check.py
import os
import requests

API_KEY = os.environ['API_NINJAS_KEY']
URL = 'https://api.api-ninjas.com/v1/validateemail'


def validate_email(email: str) -> dict:
    response = requests.get(
        URL,
        params={'email': email},
        headers={'X-Api-Key': API_KEY},
        timeout=10,
    )
    response.raise_for_status()
    return response.json()


def is_safe_to_send(email: str) -> bool:
    result = validate_email(email)
    return (
        result['is_valid']
        and result.get('mx_found', False)
        and not result.get('is_disposable', False)
    )


if __name__ == '__main__':
    for email in ['user@gmail.com', 'fake@notarealdomain.xyz', 'user@mailinator.com']:
        ok = is_safe_to_send(email)
        print(f"{'✓' if ok else '✗'} {email}")

Validating emails in a sign-up form

A Flask endpoint that rejects invalid or disposable addresses:

app.py
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route('/signup', methods=['POST'])
def signup():
    email = request.json.get('email', '')
    result = validate_email(email)
    if not result['is_valid']:
        return jsonify({'error': 'Please enter a valid email address'}), 400
    if not result.get('mx_found'):
        return jsonify({'error': 'Email domain cannot receive mail'}), 400
    if result.get('is_disposable'):
        return jsonify({'error': 'Disposable email addresses are not allowed'}), 400
    # Proceed with sign-up...
    return jsonify({'ok': True})

Bulk-validating a list of emails

Python
with open('emails.txt') as f:
    emails = [line.strip() for line in f if line.strip()]

valid = []
invalid = []
for email in emails:
    result = validate_email(email)
    (valid if result['is_valid'] else invalid).append(email)

print(f"Valid:   {len(valid)}")
print(f"Invalid: {len(invalid)}")

For lists over a few thousand, throttle requests to stay under your plan's rate limit.

Pair email validation with Validate Phone, Disposable Email Checker, or MX Lookup for deeper contact-hygiene workflows.

Frequently asked questions

What checks does the API perform?

Format validation (RFC 5322 syntax), MX record lookup (verifying the domain can receive mail), and disposable-email detection (blocks throwaway addresses like mailinator).

Does the API send a test email?

No. Validation is performed via syntax checks and DNS lookups only — no email is sent. This means the API cannot guarantee a mailbox exists, only that the domain can receive mail.

How can I detect disposable email providers?

The is_disposable field flags addresses from known throwaway providers like mailinator and 10minutemail. Reject these to keep your user base clean.

Should I validate emails client-side or server-side?

Always server-side — client-side validation can be bypassed. Use a regex for instant UI feedback, then call this API server-side before sending welcome emails or storing the address.

Is there a free tier?

Yes. Every API Ninjas account includes a free tier — no credit card required.