Skip to main content

Parse and evaluate DMARC email authentication policy

Project description

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

>>> import dmarc
>>>
>>> # represent verified SPF and DKIM status
>>> aspf = dmarc.SPF(domain='news.example.com', result=dmarc.SPF_PASS)
>>> adkim = dmarc.DKIM(domain='example.com', result=dmarc.DKIM_PASS)
>>> admarc = dmarc.DMARC() # admarc = dmarc.DMARC(publicsuffix.PublicSuffixList())
>>> try:
...     plc = admarc.parse_record(record='v=DMARC1; p=reject;', domain='example.com') # parse policy TXT RR
...     res = admarc.get_result(policy=plc, spf=aspf, dkim=adkim) # evaluate policy
...     res.verify() # check result
...     adict = res.as_dict() # dict repr
... except dmarc.RecordSyntaxError:
...     'invalid dmarc txt rr'
... except dmarc.PolicyNoneError:
...     'res.result == POLICY_FAIL and res.disposition == POLICY_DIS_NONE'
... except dmarc.PolicyQuarantineError:
...     'res.result == POLICY_FAIL and res.disposition == POLICY_DIS_QUARANTINE'
... except dmarc.PolicyRejectError:
...     'res.result == POLICY_FAIL and res.disposition == POLICY_DIS_REJECT'
... except dmarc.PolicyError:
...     'res.result == POLICY_FAIL and unknown disposition error'
...
>>> res.result == dmarc.POLICY_PASS
True
>>> res.disposition == dmarc.POLICY_DIS_NONE
True

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dmarc-1.0.3.tar.gz (5.8 kB view hashes)

Uploaded source

Built Distribution

dmarc-1.0.3-py3-none-any.whl (6.5 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page