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.SPFResult.PASS)
>>> #aspf = dmarc.SPF.from_authres(SPFAuthenticationResult(result='pass', smtp_mailfrom='email@news.example.com'))
>>>
>>> adkim = dmarc.DKIM(domain='example.com', result=dmarc.DKIMResult.PASS)
>>> #adkim = dmarc.DKIM.from_authres(DKIMAuthenticationResult(result='pass', header_d='example.com'))
>>>
>>> try:
... admarc = dmarc.DMARCPolicy(record='v=DMARC1; p=reject;', domain='example.com')
... admarc.verify(spf=aspf, dkim=adkim)
... #admarc.verify(auth_results=[aspf, adkim, dmarc.DKIM('news.example.com', dmarc.DKIMResult.FAIL)])
... adict = admarc.result.as_dict() # dict repr
... except dmarc.PolicyNoneError:
... pass
... except dmarc.PolicyQuarantineError:
... raise
... except dmarc.PolicyRejectError:
... raise
... except dmarc.RecordSyntaxError:
... raise
...
>>> # dmarc rr resolver example
>>> from dmarc.resolver import resolve, RecordNotFoundError, RecordMultiFoundError, RecordResolverError
>>> from dmarc.psl import get_public_suffix
>>> domain = 'example.com'
>>> try:
... record = resolve(domain)
... except RecordNotFoundError:
... org_domain = get_public_suffix(domain)
... if org_domain != domain:
... record = resolve(org_domain)
... except RecordMultiFoundError:
... raise # permerror
... except RecordResolverError:
... raise # temperror
...
>>> # dmarc authres header example
>>> from dmarc.ar import authres, AuthenticationResultsHeader
>>> dares = authres(admarc.result) #DMARCAuthenticationResult factory
>>> header = AuthenticationResultsHeader(authserv_id='myhostname', results=[dares])
>>> str(header)
'Authentication-Results: myhostname; dmarc=pass (domain=example.com adkim=r aspf=r p=reject pct=100) header.from=example.com policy.dmarc=none (disposition=none dkim=pass spf=pass)'
License
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.1.0.tar.gz
(16.4 kB
view details)
Built Distribution
dmarc-1.1.0-py3-none-any.whl
(21.9 kB
view details)
File details
Details for the file dmarc-1.1.0.tar.gz
.
File metadata
- Download URL: dmarc-1.1.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c434967b977187c9727bba1c0791a9638b22d41995871970eb3c6d560e827cf |
|
MD5 | 789a7dc2db24766e4f35e0d2dadd935d |
|
BLAKE2b-256 | 4e863ed95d6995008c4100353528f7f2d0f1e7e01004c0d939236fd0a2fac681 |
File details
Details for the file dmarc-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: dmarc-1.1.0-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2961e9565b2eb85cca02f62e4273179f2f3ba9e900eb69687a1558812d39167a |
|
MD5 | 67f53572154964c1586d889ccb5a5855 |
|
BLAKE2b-256 | e33ab14a4795e3a66c28510fbc319b58428d09b8fdf580c5a25445ae4be29dee |