email-auth-check 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OneGTMLab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: email-auth-check
3
+ Version: 0.1.0
4
+ Summary: Check SPF, DKIM, DMARC and MX records of a sending domain over DNS-over-HTTPS
5
+ Author: Jainendra Ojha
6
+ License: MIT
7
+ Project-URL: Homepage, https://www.onegtmlab.dev/glossary/dmarc
8
+ Project-URL: Source, https://github.com/jaizendra-netizen/email-auth-check
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ # email-auth-check
15
+
16
+ Check the email authentication records of a sending domain before you point cold email or a sequencer at it:
17
+ **SPF, DKIM, DMARC and MX**, with plain-language warnings (more than 10 SPF lookups, `+all`, `p=none`, missing `rua`, revoked DKIM key).
18
+ Records are read over DNS-over-HTTPS, so there is nothing to install: Python 3.8+ standard library only.
19
+
20
+ ```bash
21
+ python -m email_auth_check example.com
22
+ python -m email_auth_check example.com --selector google --selector selector1
23
+ python -m email_auth_check example.com --json
24
+ ```
25
+
26
+ Exit code is 1 when SPF or DMARC is missing, so it can gate a deploy or a CI step.
27
+
28
+ ## Example output (live run, 27 Nov 2026)
29
+
30
+ ```
31
+ Domain: google.com
32
+
33
+ SPF [OK] what it is: https://www.onegtmlab.dev/glossary/spf-record
34
+ v=spf1 include:_spf.google.com ~all
35
+
36
+ DKIM [not checked] pass --selector (e.g. google, selector1, k1) to test a key. What it is: https://www.onegtmlab.dev/glossary/dkim
37
+
38
+ DMARC [OK] what it is: https://www.onegtmlab.dev/glossary/dmarc
39
+ v=DMARC1; p=reject; rua=mailto:mailauth-reports@google.com
40
+
41
+ MX [OK] what it is: https://www.onegtmlab.dev/glossary/mx-record
42
+ 10 smtp.google.com
43
+ ```
44
+
45
+ ## Why these four records
46
+
47
+ Each record has its own explainer on the OneGTMLab glossary, linked in the output:
48
+ [SPF record](https://www.onegtmlab.dev/glossary/spf-record), [DKIM](https://www.onegtmlab.dev/glossary/dkim),
49
+ [DMARC](https://www.onegtmlab.dev/glossary/dmarc) and [MX record](https://www.onegtmlab.dev/glossary/mx-record).
50
+ Together they decide whether mail from a domain reaches the inbox; see also
51
+ [email deliverability](https://www.onegtmlab.dev/glossary/email-deliverability) and
52
+ [email warmup](https://www.onegtmlab.dev/glossary/email-warmup).
53
+
54
+ DKIM keys live at `<selector>._domainkey.<domain>`; the selector depends on the mail provider, so pass it with `--selector`.
55
+
56
+ ## Test
57
+
58
+ ```bash
59
+ python -m unittest discover -s tests -v # parsers and a fake resolver, no network
60
+ ```
61
+
62
+ ## Licence
63
+
64
+ MIT. Made by [OneGTMLab](https://www.onegtmlab.dev), GTM engineering for B2B teams.
@@ -0,0 +1,51 @@
1
+ # email-auth-check
2
+
3
+ Check the email authentication records of a sending domain before you point cold email or a sequencer at it:
4
+ **SPF, DKIM, DMARC and MX**, with plain-language warnings (more than 10 SPF lookups, `+all`, `p=none`, missing `rua`, revoked DKIM key).
5
+ Records are read over DNS-over-HTTPS, so there is nothing to install: Python 3.8+ standard library only.
6
+
7
+ ```bash
8
+ python -m email_auth_check example.com
9
+ python -m email_auth_check example.com --selector google --selector selector1
10
+ python -m email_auth_check example.com --json
11
+ ```
12
+
13
+ Exit code is 1 when SPF or DMARC is missing, so it can gate a deploy or a CI step.
14
+
15
+ ## Example output (live run, 27 Nov 2026)
16
+
17
+ ```
18
+ Domain: google.com
19
+
20
+ SPF [OK] what it is: https://www.onegtmlab.dev/glossary/spf-record
21
+ v=spf1 include:_spf.google.com ~all
22
+
23
+ DKIM [not checked] pass --selector (e.g. google, selector1, k1) to test a key. What it is: https://www.onegtmlab.dev/glossary/dkim
24
+
25
+ DMARC [OK] what it is: https://www.onegtmlab.dev/glossary/dmarc
26
+ v=DMARC1; p=reject; rua=mailto:mailauth-reports@google.com
27
+
28
+ MX [OK] what it is: https://www.onegtmlab.dev/glossary/mx-record
29
+ 10 smtp.google.com
30
+ ```
31
+
32
+ ## Why these four records
33
+
34
+ Each record has its own explainer on the OneGTMLab glossary, linked in the output:
35
+ [SPF record](https://www.onegtmlab.dev/glossary/spf-record), [DKIM](https://www.onegtmlab.dev/glossary/dkim),
36
+ [DMARC](https://www.onegtmlab.dev/glossary/dmarc) and [MX record](https://www.onegtmlab.dev/glossary/mx-record).
37
+ Together they decide whether mail from a domain reaches the inbox; see also
38
+ [email deliverability](https://www.onegtmlab.dev/glossary/email-deliverability) and
39
+ [email warmup](https://www.onegtmlab.dev/glossary/email-warmup).
40
+
41
+ DKIM keys live at `<selector>._domainkey.<domain>`; the selector depends on the mail provider, so pass it with `--selector`.
42
+
43
+ ## Test
44
+
45
+ ```bash
46
+ python -m unittest discover -s tests -v # parsers and a fake resolver, no network
47
+ ```
48
+
49
+ ## Licence
50
+
51
+ MIT. Made by [OneGTMLab](https://www.onegtmlab.dev), GTM engineering for B2B teams.
@@ -0,0 +1,124 @@
1
+ """Check SPF, DKIM, DMARC and MX records of a sending domain (DNS over HTTPS, stdlib only)."""
2
+ import json, re, urllib.parse, urllib.request
3
+
4
+ __version__ = "0.1.0"
5
+ GLOSSARY = {
6
+ "spf": "https://www.onegtmlab.dev/glossary/spf-record",
7
+ "dkim": "https://www.onegtmlab.dev/glossary/dkim",
8
+ "dmarc": "https://www.onegtmlab.dev/glossary/dmarc",
9
+ "mx": "https://www.onegtmlab.dev/glossary/mx-record",
10
+ }
11
+ DOH = "https://cloudflare-dns.com/dns-query"
12
+
13
+
14
+ def doh_txt(name, rtype="TXT", timeout=10):
15
+ """Resolve `name` over DNS-over-HTTPS. Returns a list of record strings (TXT quotes removed)."""
16
+ url = DOH + "?" + urllib.parse.urlencode({"name": name, "type": rtype})
17
+ req = urllib.request.Request(url, headers={"accept": "application/dns-json", "User-Agent": "email-auth-check/" + __version__})
18
+ data = json.load(urllib.request.urlopen(req, timeout=timeout))
19
+ out = []
20
+ for a in data.get("Answer", []) or []:
21
+ v = a.get("data", "")
22
+ if rtype == "TXT":
23
+ v = "".join(re.findall(r'"((?:[^"\\]|\\.)*)"', v)) or v.strip('"')
24
+ out.append(v)
25
+ return out
26
+
27
+
28
+ def parse_spf(records):
29
+ spf = [r for r in records if r.lower().startswith("v=spf1")]
30
+ res = {"found": bool(spf), "record": spf[0] if spf else None, "issues": [], "lookups": 0, "all": None}
31
+ if not spf:
32
+ res["issues"].append("no SPF record (v=spf1) published")
33
+ return res
34
+ if len(spf) > 1:
35
+ res["issues"].append("more than one SPF record: receivers treat this as a permanent error")
36
+ terms = spf[0].split()[1:]
37
+ for t in terms:
38
+ tt = t.lstrip("+-~?").lower()
39
+ if tt.split(":")[0].split("=")[0] in ("include", "a", "mx", "ptr", "exists", "redirect"):
40
+ res["lookups"] += 1
41
+ if tt == "all":
42
+ res["all"] = t
43
+ if res["lookups"] > 10:
44
+ res["issues"].append("%d DNS-lookup terms in this record; SPF allows at most 10" % res["lookups"])
45
+ if res["all"] is None and not any(t.lower().startswith("redirect=") for t in terms):
46
+ res["issues"].append("no 'all' mechanism at the end")
47
+ elif res["all"] and res["all"].startswith("+"):
48
+ res["issues"].append("'+all' authorises every server on the internet")
49
+ elif res["all"] == "all":
50
+ res["issues"].append("bare 'all' means +all, which authorises every server")
51
+ if any(t.lower().lstrip("+-~?") == "ptr" or t.lower().startswith("ptr:") for t in terms):
52
+ res["issues"].append("'ptr' is deprecated")
53
+ return res
54
+
55
+
56
+ def _tags(record):
57
+ out = {}
58
+ for part in record.split(";"):
59
+ if "=" in part:
60
+ k, v = part.split("=", 1)
61
+ out[k.strip().lower()] = v.strip()
62
+ return out
63
+
64
+
65
+ def parse_dmarc(records):
66
+ d = [r for r in records if r.lower().replace(" ", "").startswith("v=dmarc1")]
67
+ res = {"found": bool(d), "record": d[0] if d else None, "policy": None, "issues": []}
68
+ if not d:
69
+ res["issues"].append("no DMARC record at _dmarc.<domain>")
70
+ return res
71
+ tags = _tags(d[0])
72
+ res["policy"] = tags.get("p", "").lower() or None
73
+ res["rua"] = tags.get("rua")
74
+ res["pct"] = tags.get("pct")
75
+ if res["policy"] not in ("none", "quarantine", "reject"):
76
+ res["issues"].append("missing or invalid p= policy")
77
+ elif res["policy"] == "none":
78
+ res["issues"].append("p=none only monitors; nothing is quarantined or rejected")
79
+ if not tags.get("rua"):
80
+ res["issues"].append("no rua= address, so no aggregate reports")
81
+ if tags.get("pct") not in (None, "100"):
82
+ res["issues"].append("pct=%s applies the policy to only part of the mail" % tags.get("pct"))
83
+ return res
84
+
85
+
86
+ def parse_dkim(records):
87
+ d = [r for r in records if "p=" in r.replace(" ", "").lower() or r.lower().replace(" ", "").startswith("v=dkim1")]
88
+ res = {"found": bool(d), "record": d[0] if d else None, "issues": []}
89
+ if not d:
90
+ res["issues"].append("no DKIM key at this selector")
91
+ return res
92
+ tags = _tags(d[0])
93
+ if not tags.get("p"):
94
+ res["issues"].append("empty p= means this key has been revoked")
95
+ if tags.get("k", "rsa").lower() == "rsa" and tags.get("p") and len(tags["p"]) < 200:
96
+ res["issues"].append("RSA key looks shorter than 1024 bits")
97
+ return res
98
+
99
+
100
+ def parse_mx(records):
101
+ mx = []
102
+ for r in records:
103
+ bits = r.split()
104
+ if len(bits) == 2 and bits[0].isdigit():
105
+ mx.append((int(bits[0]), bits[1].rstrip(".").lower()))
106
+ mx.sort()
107
+ res = {"found": bool(mx), "hosts": mx, "issues": []}
108
+ if not mx:
109
+ res["issues"].append("no MX record: the domain cannot receive mail")
110
+ return res
111
+
112
+
113
+ def check(domain, selectors=(), resolver=doh_txt):
114
+ domain = domain.strip().lower().rstrip(".")
115
+ out = {
116
+ "domain": domain,
117
+ "spf": parse_spf(resolver(domain, "TXT")),
118
+ "dmarc": parse_dmarc(resolver("_dmarc." + domain, "TXT")),
119
+ "mx": parse_mx(resolver(domain, "MX")),
120
+ "dkim": {},
121
+ }
122
+ for s in selectors:
123
+ out["dkim"][s] = parse_dkim(resolver("%s._domainkey.%s" % (s, domain), "TXT"))
124
+ return out
@@ -0,0 +1,35 @@
1
+ import argparse, json, sys
2
+ from . import check, GLOSSARY
3
+
4
+
5
+ def render(r):
6
+ lines = ["Domain: " + r["domain"], ""]
7
+ def sec(name, key, ok, detail, issues):
8
+ lines.append("%s [%s] what it is: %s" % (name, "OK" if ok and not issues else ("WARN" if ok else "MISSING"), GLOSSARY[key]))
9
+ if detail: lines.append(" " + detail)
10
+ for i in issues: lines.append(" - " + i)
11
+ lines.append("")
12
+ sec("SPF", "spf", r["spf"]["found"], r["spf"]["record"], r["spf"]["issues"])
13
+ for s, d in r["dkim"].items():
14
+ sec("DKIM (%s)" % s, "dkim", d["found"], (d["record"] or "")[:100], d["issues"])
15
+ if not r["dkim"]:
16
+ lines.append("DKIM [not checked] pass --selector (e.g. google, selector1, k1) to test a key. What it is: " + GLOSSARY["dkim"] + "\n")
17
+ sec("DMARC", "dmarc", r["dmarc"]["found"], r["dmarc"]["record"], r["dmarc"]["issues"])
18
+ sec("MX", "mx", r["mx"]["found"], ", ".join("%d %s" % h for h in r["mx"]["hosts"]), r["mx"]["issues"])
19
+ return "\n".join(lines)
20
+
21
+
22
+ def main(argv=None):
23
+ p = argparse.ArgumentParser(prog="email-auth-check", description="Check SPF, DKIM, DMARC and MX for a sending domain.")
24
+ p.add_argument("domain")
25
+ p.add_argument("--selector", "-s", action="append", default=[], help="DKIM selector to test (repeatable)")
26
+ p.add_argument("--json", action="store_true")
27
+ a = p.parse_args(argv)
28
+ r = check(a.domain, a.selector)
29
+ print(json.dumps(r, indent=1) if a.json else render(r))
30
+ bad = not (r["spf"]["found"] and r["dmarc"]["found"])
31
+ return 1 if bad else 0
32
+
33
+
34
+ if __name__ == "__main__":
35
+ sys.exit(main())
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: email-auth-check
3
+ Version: 0.1.0
4
+ Summary: Check SPF, DKIM, DMARC and MX records of a sending domain over DNS-over-HTTPS
5
+ Author: Jainendra Ojha
6
+ License: MIT
7
+ Project-URL: Homepage, https://www.onegtmlab.dev/glossary/dmarc
8
+ Project-URL: Source, https://github.com/jaizendra-netizen/email-auth-check
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ # email-auth-check
15
+
16
+ Check the email authentication records of a sending domain before you point cold email or a sequencer at it:
17
+ **SPF, DKIM, DMARC and MX**, with plain-language warnings (more than 10 SPF lookups, `+all`, `p=none`, missing `rua`, revoked DKIM key).
18
+ Records are read over DNS-over-HTTPS, so there is nothing to install: Python 3.8+ standard library only.
19
+
20
+ ```bash
21
+ python -m email_auth_check example.com
22
+ python -m email_auth_check example.com --selector google --selector selector1
23
+ python -m email_auth_check example.com --json
24
+ ```
25
+
26
+ Exit code is 1 when SPF or DMARC is missing, so it can gate a deploy or a CI step.
27
+
28
+ ## Example output (live run, 27 Nov 2026)
29
+
30
+ ```
31
+ Domain: google.com
32
+
33
+ SPF [OK] what it is: https://www.onegtmlab.dev/glossary/spf-record
34
+ v=spf1 include:_spf.google.com ~all
35
+
36
+ DKIM [not checked] pass --selector (e.g. google, selector1, k1) to test a key. What it is: https://www.onegtmlab.dev/glossary/dkim
37
+
38
+ DMARC [OK] what it is: https://www.onegtmlab.dev/glossary/dmarc
39
+ v=DMARC1; p=reject; rua=mailto:mailauth-reports@google.com
40
+
41
+ MX [OK] what it is: https://www.onegtmlab.dev/glossary/mx-record
42
+ 10 smtp.google.com
43
+ ```
44
+
45
+ ## Why these four records
46
+
47
+ Each record has its own explainer on the OneGTMLab glossary, linked in the output:
48
+ [SPF record](https://www.onegtmlab.dev/glossary/spf-record), [DKIM](https://www.onegtmlab.dev/glossary/dkim),
49
+ [DMARC](https://www.onegtmlab.dev/glossary/dmarc) and [MX record](https://www.onegtmlab.dev/glossary/mx-record).
50
+ Together they decide whether mail from a domain reaches the inbox; see also
51
+ [email deliverability](https://www.onegtmlab.dev/glossary/email-deliverability) and
52
+ [email warmup](https://www.onegtmlab.dev/glossary/email-warmup).
53
+
54
+ DKIM keys live at `<selector>._domainkey.<domain>`; the selector depends on the mail provider, so pass it with `--selector`.
55
+
56
+ ## Test
57
+
58
+ ```bash
59
+ python -m unittest discover -s tests -v # parsers and a fake resolver, no network
60
+ ```
61
+
62
+ ## Licence
63
+
64
+ MIT. Made by [OneGTMLab](https://www.onegtmlab.dev), GTM engineering for B2B teams.
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ email_auth_check/__init__.py
5
+ email_auth_check/__main__.py
6
+ email_auth_check.egg-info/PKG-INFO
7
+ email_auth_check.egg-info/SOURCES.txt
8
+ email_auth_check.egg-info/dependency_links.txt
9
+ email_auth_check.egg-info/entry_points.txt
10
+ email_auth_check.egg-info/top_level.txt
11
+ tests/test_parsers.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ email-auth-check = email_auth_check.__main__:main
@@ -0,0 +1 @@
1
+ email_auth_check
@@ -0,0 +1,15 @@
1
+ [project]
2
+ name = "email-auth-check"
3
+ version = "0.1.0"
4
+ description = "Check SPF, DKIM, DMARC and MX records of a sending domain over DNS-over-HTTPS"
5
+ license = { text = "MIT" }
6
+ readme = "README.md"
7
+ authors = [{ name = "Jainendra Ojha" }]
8
+ requires-python = ">=3.8"
9
+
10
+ [project.scripts]
11
+ email-auth-check = "email_auth_check.__main__:main"
12
+
13
+ [project.urls]
14
+ Homepage = "https://www.onegtmlab.dev/glossary/dmarc"
15
+ Source = "https://github.com/jaizendra-netizen/email-auth-check"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,44 @@
1
+ import os, sys, unittest
2
+ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
3
+ from email_auth_check import parse_spf, parse_dmarc, parse_dkim, parse_mx, check
4
+
5
+
6
+ class T(unittest.TestCase):
7
+ def test_spf_ok(self):
8
+ r = parse_spf(["google-site-verification=x", "v=spf1 include:_spf.google.com ~all"])
9
+ self.assertTrue(r["found"]); self.assertEqual(r["lookups"], 1); self.assertEqual(r["issues"], [])
10
+
11
+ def test_spf_missing_and_plus_all(self):
12
+ self.assertFalse(parse_spf(["hello"])["found"])
13
+ self.assertTrue(any("+all" in i for i in parse_spf(["v=spf1 +all"])["issues"]))
14
+
15
+ def test_spf_too_many_lookups_and_duplicates(self):
16
+ rec = "v=spf1 " + " ".join("include:s%d.example.com" % i for i in range(11)) + " -all"
17
+ self.assertTrue(any("at most 10" in i for i in parse_spf([rec])["issues"]))
18
+ self.assertTrue(any("more than one" in i for i in parse_spf(["v=spf1 -all", "v=spf1 ~all"])["issues"]))
19
+
20
+ def test_dmarc(self):
21
+ r = parse_dmarc(["v=DMARC1; p=reject; rua=mailto:d@example.com; pct=100"])
22
+ self.assertEqual(r["policy"], "reject"); self.assertEqual(r["issues"], [])
23
+ r = parse_dmarc(["v=DMARC1; p=none"])
24
+ self.assertEqual(len(r["issues"]), 2)
25
+ self.assertFalse(parse_dmarc([])["found"])
26
+
27
+ def test_dkim(self):
28
+ self.assertTrue(parse_dkim(["v=DKIM1; k=rsa; p=" + "A" * 220])["found"])
29
+ self.assertTrue(any("revoked" in i for i in parse_dkim(["v=DKIM1; p="])["issues"]))
30
+ self.assertFalse(parse_dkim([])["found"])
31
+
32
+ def test_mx_sorted(self):
33
+ r = parse_mx(["20 b.example.com.", "10 a.example.com."])
34
+ self.assertEqual(r["hosts"][0], (10, "a.example.com"))
35
+
36
+ def test_check_with_fake_resolver(self):
37
+ db = {("ex.com", "TXT"): ["v=spf1 -all"], ("_dmarc.ex.com", "TXT"): ["v=DMARC1; p=quarantine; rua=mailto:a@ex.com"],
38
+ ("ex.com", "MX"): ["10 mx.ex.com."], ("s1._domainkey.ex.com", "TXT"): ["v=DKIM1; p=" + "B" * 220]}
39
+ r = check("EX.com.", ["s1"], resolver=lambda n, t: db.get((n, t), []))
40
+ self.assertTrue(r["spf"]["found"] and r["dmarc"]["found"] and r["mx"]["found"] and r["dkim"]["s1"]["found"])
41
+
42
+
43
+ if __name__ == "__main__":
44
+ unittest.main()