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

MX Lookup API

The MX Lookup API retrieves mail exchange (MX) records for any given domain.

Online
(4.7)

From 5,110 users

4,200+

Applications using this API

API Status

Online - All Systems Operational

API Response Times

Average
P50
P75
P90
P95
328ms377ms375ms726ms1006ms

Didn't find what you were looking for? Suggest an improvement

https://api.api-ninjas.com/v1/mxlookup

Returns a list of MX records associated with a particular domain. Free users receive only data from the first MX record, while premium users get access to all MX records.

Parameters

  • domain  required

    Valid domain to check (e.g. x.com). All top-level domains are supported.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

The /v1/mxlookup endpoint returns a JSON array of objects, each with the following fields, or an error if the request is unsuccessful.

  • priority

    Priority value of the MX record (lower numbers indicate higher priority).

  • value

    The mail server hostname.

Live Demo

Live demo · no API key required
Query parameters
domain

Get a free API key to get started — no credit card required.

Headers
X-Api-KeyLog in or sign up to get your API key
GET
https://api.api-ninjas.com/v1/mxlookup?domain=x.com
Sample response
[
{
"priority": 5,
"value": "alt2.aspmx.l.google.com."
},
{
"priority": 1,
"value": "aspmx.l.google.com."
},
{
"priority": 10,
"value": "alt3.aspmx.l.google.com."
},
{
"priority": 10,
"value": "alt4.aspmx.l.google.com."
},
{
"priority": 5,
"value": "alt1.aspmx.l.google.com."
}
]

Code Examples

curl -X GET "https://api.api-ninjas.com/v1/mxlookup?domain=example.com" \ -H "X-Api-Key: YOUR_API_KEY"

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.

Frequently Asked Questions

  • Yes, but you must have a premium subscription. Commercial use of the MX Lookup API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.
  • Sign up for a free account to instantly get your API key, then pass it in the X-Api-Key header on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.
  • Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.
  • The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.
  • You can use the MX Lookup API to verify that a domain is configured to receive email, identify a domain's mail provider, and troubleshoot email deliverability issues. It pairs well with the Validate Email API and Disposable Email Checker API for building robust email verification pipelines.
  • Send a GET request to the /v1/mxlookup endpoint with the required domain parameter set to the domain you want to check (e.g. x.com); all top-level domains are supported. See the API directory for related lookup tools like the DNS Lookup API.
  • The response is a JSON array of objects, each containing a priority field (lower numbers indicate higher priority) and a value field with the mail server hostname, or an error if the request fails.
  • Free users receive data only from the first MX record, while premium users get access to all MX records associated with the domain; see pricing for plan details.