1
0
Fork 0
mirror of https://gitlab.com/duobradovic/pydmarc.git synced 2025-12-16 03:13:09 +00:00
DMARC library and milter module implemented in Python.
Find a file
2025-08-07 15:01:07 +02:00
conf Update dmarcmilter.toml with new settings 2025-08-07 15:01:07 +02:00
contrib Milter 2025-03-19 11:48:11 +00:00
dmarc Update config with backwards-compatible defaults 2025-08-07 14:57:07 +02:00
.gitlab-ci.yml Milter 2025-03-19 11:48:11 +00:00
LICENSE Initial commit 2019-10-15 10:49:38 +02:00
README.md Update docstring 2025-07-21 18:54:05 +02:00
setup.py 1.1.2 2025-03-25 21:23:58 +01:00

DMARC (Domain-based Message Authentication, Reporting & Conformance)

DMARC email authentication module implemented in Python.

Installation

Use the package manager pip to install dmarc.

$ pip install dmarc

Usage

>>> from dmarc import SPFAuthResult, DKIMAuthResult, SPFResult, DKIMResult, DMARCPolicy
>>> # Represent verified SPF and DKIM identifiers
>>> spf = SPFAuthResult('news.example.com', SPFResult('pass'))
>>> dkim = DKIMAuthResult('example.com', DKIMResult('pass'))
>>> policy = DMARCPolicy(record='v=DMARC1; p=reject;', domain='example.com')
>>> policy.verify(auth_results=[spf, dkim])
>>> 
>>> # RR resolver example
>>> from dmarc.resolver import resolve, RecordNotFoundError, RecordMultiFoundError
>>> from dmarc.psl import get_public_suffix
>>> domain = 'news.example.com'
>>> try:
...     record = resolve(domain)
... except (RecordNotFoundError, RecordMultiFoundError):
...     org_domain = get_public_suffix(domain)
...     if org_domain != domain:
...         record = resolve(org_domain)
... 
>>> # Aggregate report xml document to dict example
>>> from dmarc.report import DMARCRelaxedSchema
>>> from dmarc.tests.report.test_report import TEST_XML_DOCUMENT
>>> adict = DMARCRelaxedSchema.to_dict(TEST_XML_DOCUMENT)
>>> 

Milter configuration with Postfix

  1. Start dmarc.milter module or run via Systemd — see contrib/.
  2. Start a Postfix instance with a configuration like smtpd_milters = inet:127.0.0.1:9000

Described here 👉 Run DMARC Milter with Postfix.

License

MIT