# Email authentication

> POST /email/auth checks SPF, DMARC, DKIM, MTA-STS, TLS-RPT, BIMI and MX of a sending domain and returns a grade from A to F with the exact fixes.

`POST https://api.qelka.com/v1/email/auth`

Grade the email authentication of a sending domain in one call: SPF and its 10-lookup limit, DMARC, DKIM keys, BIMI, MTA-STS with its policy file, TLS-RPT and MX, with a score, a grade from A to F and the fixes to apply, each with the DNS record to publish. Each check costs 1 credit.

## Request

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `domain` | string | Yes | none | A sending domain (`example.com`), or an email address whose domain is used. |
| `selectors` | array of strings | No | none | Up to 10 DKIM selectors to check besides the 28 common ones, such as the `s=` value of a DKIM-Signature header you received. |
| `fresh` | boolean | No | `false` | `true` skips the 1-hour result cache. |

```bash title="cURL"
curl https://api.qelka.com/v1/email/auth \
  --max-time 30 \
  -H "Authorization: Bearer $QELKA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"domain": "github.com", "selectors": ["pm"]}'
```
```javascript title="Node.js"
const response = await fetch('https://api.qelka.com/v1/email/auth', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ domain: 'github.com', selectors: ['pm'] }),
  signal: AbortSignal.timeout(30_000),
})
const result = await response.json()
console.log(result)
```
```python title="Python"
import os

import requests

api_key = os.environ["QELKA_API_KEY"]
response = requests.post(
    "https://api.qelka.com/v1/email/auth",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"domain": "github.com", "selectors": ["pm"]},
    timeout=30,
)
result = response.json()
print(result)
```
```php title="PHP"
<?php
$ch = curl_init('https://api.qelka.com/v1/email/auth');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer ' . getenv('QELKA_API_KEY'),
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode(['domain' => 'github.com', 'selectors' => ['pm']]),
    CURLOPT_TIMEOUT => 30,
]);
$result = json_decode(curl_exec($ch), true);
print_r($result);
```
```go title="Go"
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"net/http"
	"os"
	"time"
)

func main() {
	payload, _ := json.Marshal(map[string]any{"domain": "github.com", "selectors": []string{"pm"}})
	request, _ := http.NewRequest(http.MethodPost, "https://api.qelka.com/v1/email/auth", bytes.NewReader(payload))
	request.Header.Set("Authorization", "Bearer "+os.Getenv("QELKA_API_KEY"))
	request.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 30 * time.Second}
	response, err := client.Do(request)
	if err != nil {
		panic(err)
	}
	defer response.Body.Close()

	var result map[string]any
	if err := json.NewDecoder(response.Body).Decode(&result); err != nil {
		panic(err)
	}
	fmt.Println(result)
}
```
```ruby title="Ruby"
require 'json'
require 'net/http'

uri = URI('https://api.qelka.com/v1/email/auth')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{ENV.fetch('QELKA_API_KEY')}"
request['Content-Type'] = 'application/json'
request.body = JSON.generate({ domain: 'github.com', selectors: ['pm'] })

response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 30) do |http|
  http.request(request)
end
result = JSON.parse(response.body)
puts result
```

## Response

| Field | Type | Description |
|---|---|---|
| `id` | string | Identifier of this lookup. |
| `object` | string | Always `email_auth`. |
| `input` | string | The `domain` you sent. |
| `domain` | string | The domain checked. |
| `grade` | string | `A`, `B`, `C`, `D` or `F`. See [Grade](#grade). |
| `score` | integer | From 0 to 100. |
| `mx` | object | `status` of the MX lookup, `records` (`priority`, `exchange`), `null_mx` and the `provider` recognized from the hosts. |
| `spf` | object | `record`, `records_found`, `valid`, `all` (`pass`, `fail`, `softfail`, `neutral` or `null`), `mechanisms`, `dns_lookups`, `lookup_limit` (10) and `issues`. |
| `dmarc` | object | `record`, `valid`, `policy`, `subdomain_policy`, `pct`, `rua`, `ruf`, `adkim`, `aspf` and `issues`. |
| `dkim.selectors_checked` | array of strings | The common selectors, then the ones you sent. |
| `dkim.keys` | array of objects | Selectors that publish a key: `selector`, `valid`, `key_type`, `key_bits`, `testing`, `revoked` and `issues`. A single selector `*` means every selector returned the same record: a wildcard, often a revoked key on a domain that sends no mail. |
| `bimi` | object | `record` at `default._bimi`, `valid`, `logo_url`, `authority_url` and `issues`. |
| `mta_sts` | object | `record` at `_mta-sts`, its `id`, `policy_status` (`ok`, `not_found`, `invalid`, `unreachable` or `null` without a record), `mode`, `max_age`, `mx` and `issues`. |
| `tls_rpt` | object | `record` at `_smtp._tls`, `valid`, `rua` and `issues`. |
| `fixes` | array of objects | What to change, most important first: `code`, `severity` (`critical`, `warning` or `info`), `area`, `message` and `record`, the DNS record to publish (`name`, `type`, `value`) or `null`. Values in angle brackets are placeholders only the domain owner can fill. |
| `checked_at` | string | Time of the check, ISO 8601. |
| `credits_used` | integer | Credits debited for this call: 1 with a live key when the result is billed, else `0`. |
| `cached` | boolean | `true` when the answer came from the 1-hour cache. |

```json title="Response"
{
  "id": "lkp_01M8CGD47HPCSHCN5SVATD9ZRX",
  "object": "email_auth",
  "input": "github.com",
  "domain": "github.com",
  "grade": "B",
  "score": 89,
  "mx": {
    "status": "NOERROR",
    "records": [
      {"priority": 0, "exchange": "github-com.mail.protection.outlook.com"}
    ],
    "null_mx": false,
    "provider": "Microsoft 365"
  },
  "spf": {
    "record": "v=spf1 ip4:192.30.252.0/22 ip4:172.170.10.240/28 ip4:40.78.162.192/28 ip4:172.170.3.48/28 include:spf.protection.outlook.com include:_netblocks.google.com include:_netblocks2.google.com include:mail.zendesk.com include:_spf.salesforce.com include:servers.mcsv.net include:mktomail.com include:sendgrid.net ip4:62.253.227.114 ip4:166.78.69.169 ip4:166.78.69.170 ip4:166.78.71.131 ~all",
    "records_found": 1,
    "valid": true,
    "all": "softfail",
    "mechanisms": [
      {"qualifier": "+", "type": "ip4", "value": "192.30.252.0/22"},
      {"qualifier": "+", "type": "ip4", "value": "172.170.10.240/28"},
      {"qualifier": "+", "type": "ip4", "value": "40.78.162.192/28"},
      {"qualifier": "+", "type": "ip4", "value": "172.170.3.48/28"},
      {"qualifier": "+", "type": "include", "value": "spf.protection.outlook.com"},
      {"qualifier": "+", "type": "include", "value": "_netblocks.google.com"},
      {"qualifier": "+", "type": "include", "value": "_netblocks2.google.com"},
      {"qualifier": "+", "type": "include", "value": "mail.zendesk.com"},
      {"qualifier": "+", "type": "include", "value": "_spf.salesforce.com"},
      {"qualifier": "+", "type": "include", "value": "servers.mcsv.net"},
      {"qualifier": "+", "type": "include", "value": "mktomail.com"},
      {"qualifier": "+", "type": "include", "value": "sendgrid.net"},
      {"qualifier": "+", "type": "ip4", "value": "62.253.227.114"},
      {"qualifier": "+", "type": "ip4", "value": "166.78.69.169"},
      {"qualifier": "+", "type": "ip4", "value": "166.78.69.170"},
      {"qualifier": "+", "type": "ip4", "value": "166.78.71.131"},
      {"qualifier": "~", "type": "all", "value": null}
    ],
    "dns_lookups": 10,
    "lookup_limit": 10,
    "issues": []
  },
  "dmarc": {
    "record": "v=DMARC1; p=quarantine; sp=reject; pct=100; rua=mailto:dmarc@github.com; ruf=mailto:dmarc@github.com; fo=1",
    "valid": true,
    "policy": "quarantine",
    "subdomain_policy": "reject",
    "pct": 100,
    "rua": ["mailto:dmarc@github.com"],
    "ruf": ["mailto:dmarc@github.com"],
    "adkim": "r",
    "aspf": "r",
    "issues": []
  },
  "dkim": {
    "selectors_checked": [
      "google",
      "selector1",
      "selector2",
      "k1",
      "k2",
      "k3",
      "s1",
      "s2",
      "default",
      "dkim",
      "mail",
      "smtp",
      "mandrill",
      "mxvault",
      "zmail",
      "zoho",
      "protonmail",
      "protonmail2",
      "protonmail3",
      "fm1",
      "fm2",
      "fm3",
      "sig1",
      "mailjet",
      "krs",
      "mailo",
      "cm",
      "everlytickey1"
    ],
    "keys": [
      {"selector": "google", "valid": true, "key_type": "rsa", "key_bits": 2048, "testing": false, "revoked": false, "issues": []},
      {"selector": "selector1", "valid": true, "key_type": "rsa", "key_bits": 1024, "testing": false, "revoked": false, "issues": ["short_key"]},
      {"selector": "k1", "valid": true, "key_type": "rsa", "key_bits": 1024, "testing": false, "revoked": false, "issues": ["short_key"]},
      {"selector": "k2", "valid": true, "key_type": "rsa", "key_bits": 2048, "testing": false, "revoked": false, "issues": []},
      {"selector": "k3", "valid": true, "key_type": "rsa", "key_bits": 2048, "testing": false, "revoked": false, "issues": []},
      {"selector": "s1", "valid": true, "key_type": "rsa", "key_bits": 2048, "testing": false, "revoked": false, "issues": []},
      {"selector": "s2", "valid": true, "key_type": "rsa", "key_bits": 2048, "testing": false, "revoked": false, "issues": []},
      {"selector": "mailo", "valid": true, "key_type": "rsa", "key_bits": 1024, "testing": false, "revoked": false, "issues": ["short_key"]},
      {"selector": "cm", "valid": true, "key_type": "rsa", "key_bits": 1024, "testing": false, "revoked": false, "issues": ["short_key"]}
    ]
  },
  "bimi": {
    "record": null,
    "valid": false,
    "logo_url": null,
    "authority_url": null,
    "issues": []
  },
  "mta_sts": {
    "record": null,
    "id": null,
    "policy_status": null,
    "mode": null,
    "max_age": null,
    "mx": [],
    "issues": []
  },
  "tls_rpt": {
    "record": null,
    "valid": false,
    "rua": [],
    "issues": []
  },
  "fixes": [
    {
      "code": "rotate_dkim_key",
      "severity": "info",
      "area": "dkim",
      "message": "These DKIM keys are shorter than 2048-bit RSA: selector1._domainkey.github.com (1024-bit), k1._domainkey.github.com (1024-bit), mailo._domainkey.github.com (1024-bit), cm._domainkey.github.com (1024-bit). Rotate to 2048-bit keys from your sending service.",
      "record": null
    },
    {
      "code": "add_mta_sts",
      "severity": "info",
      "area": "mta_sts",
      "message": "Without MTA-STS, a network attacker can strip TLS from mail sent to github.com. Serve https://mta-sts.github.com/.well-known/mta-sts.txt with the lines version: STSv1, mode: testing, mx: github-com.mail.protection.outlook.com, max_age: 604800, then publish this record. Switch to mode: enforce once TLS reports are clean.",
      "record": {
        "name": "_mta-sts.github.com",
        "type": "TXT",
        "value": "v=STSv1; id=202611261803"
      }
    },
    {
      "code": "add_tls_rpt",
      "severity": "info",
      "area": "tls_rpt",
      "message": "Publish a TLS-RPT record so sending servers report TLS failures when delivering to github.com.",
      "record": {
        "name": "_smtp._tls.github.com",
        "type": "TXT",
        "value": "v=TLSRPTv1; rua=mailto:<tls-reports@github.com>"
      }
    },
    {
      "code": "add_bimi",
      "severity": "info",
      "area": "bimi",
      "message": "DMARC is enforced, so github.com can show its logo next to messages with BIMI. Publish the logo as an SVG Tiny PS file over HTTPS; Gmail and Apple Mail also need a Verified Mark Certificate or Common Mark Certificate (a=).",
      "record": {
        "name": "default._bimi.github.com",
        "type": "TXT",
        "value": "v=BIMI1; l=<https://github.com/logo.svg>; a=<https://github.com/mark-certificate.pem>"
      }
    }
  ],
  "checked_at": "2026-11-26T18:03:10.448Z",
  "credits_used": 1,
  "cached": false
}
```

## Grade

The score starts at 100 and each fix takes points off: 30 for a missing DMARC record, 25 for a missing SPF record, 20 for several SPF or DMARC records, 15 for SPF ending in `+all`, above 10 lookups or with a syntax error, 15 for a DMARC syntax error or `p=none`, 10 for no DKIM key or a broken one, 8 for SPF ending in `?all` or without `all`, 5 for no DMARC report address, `pct` below 100, no MX, no MTA-STS or an invalid policy, 3 for a short or testing DKIM key, MTA-STS in testing or a TLS-RPT problem, 2 for an invalid BIMI record.

Then caps apply: without SPF and DMARC the score is at most 39; without one of them, at most 59; without DMARC enforcement (`quarantine` or `reject` at `pct=100`), at most 89. Grades: A from 90, B from 75, C from 60, D from 40, F below. MTA-STS and TLS-RPT only count for domains that receive mail. A domain with no MX and an SPF record of `-all` only is treated as parked: DKIM, MX and BIMI are not graded.

## Fix codes

`add_spf`, `merge_spf_records`, `fix_spf_syntax`, `reduce_spf_lookups`, `restrict_spf_all`, `add_dmarc`, `merge_dmarc_records`, `fix_dmarc_syntax`, `enforce_dmarc`, `raise_dmarc_pct`, `add_dmarc_rua`, `add_dkim`, `fix_dkim_key`, `rotate_dkim_key`, `leave_dkim_testing`, `add_mx`, `add_mta_sts`, `fix_mta_sts_policy`, `enforce_mta_sts`, `add_tls_rpt`, `fix_tls_rpt`, `add_bimi` and `fix_bimi`. Show `message` to people and branch on `code` in code.

## How the domain is checked

DNS records are read over DNS over HTTPS, Cloudflare first and Google Public DNS as a fallback. SPF includes and redirects are followed to count lookups as [RFC 7208](https://www.rfc-editor.org/rfc/rfc7208) does. The MTA-STS policy is fetched from `https://mta-sts.{domain}/.well-known/mta-sts.txt`; as [RFC 8461](https://www.rfc-editor.org/rfc/rfc8461) requires, a policy served through a redirect is invalid. No mail is sent, and DKIM keys on selectors that are neither common nor sent in `selectors` are not found.

## Batch and bulk

Send up to 100 domains in one [batch](https://qelka.com/docs/api-reference/batch) with `"type": "email_auth"`, or a CSV column of domains or addresses as a [bulk job](https://qelka.com/docs/api-reference/bulk): the output adds the grade, score, mail provider, SPF record and lookups, DMARC policy, DKIM selectors found, BIMI, MTA-STS mode, TLS-RPT and the fix codes. The MCP tool is `grade_email_auth`.
