research/reading-dmarc-aggregate-reports

Reading DMARC Aggregate Reports: A Standard-Library Python Parser for the XML Providers Send Back

Engineering Note · November 19, 2026 · 10 minute read · Email · DMARC · Python

A DMARC aggregate report is an XML file a mailbox provider sends to the address in your DMARC record. Each <record> covers one sending IP address: how many messages used your domain in the From line, what the provider did with them, and how they did on SPF and DKIM. About 60 lines of standard-library Python can open plain, gzipped or zipped reports and print one row per sender. To read a row, compare policy_evaluated, the provider’s DMARC verdict, with auth_results, the raw evidence behind it.

Everything below was run with Python 3.11.18 (bundled expat 2.6.1) and, for one comparison, defusedxml 0.7.1. We have no DMARC reports of our own to show, so we used the sample reports in the open-source parsedmarc project (Apache 2.0 license), release 11.3.0. Some name the provider that sent them, such as Outlook.com, with the owner’s domain replaced by example.com. Others are plainly test files. All output below is pasted from our run.

This follows our November 10 article, Email That Arrives, which recommends starting DMARC at p=none and reading the reports.

What is inside an aggregate report?

The published RFCs were not reachable from here, so we worked from the DMARC working group’s source for its aggregate reporting draft (draft 32, March 2025). parsedmarc’s README says the final schema is RFC 9990.

The draft describes report_metadata (with a date_range in “seconds since epoch”), policy_published (the DMARC record the reporter found) and one record per sender, holding source_ip, count, policy_evaluated, identifiers (including header_from, the visible From domain) and auth_results.

policy_evaluated, in the draft’s words, holds “the result of the DKIM DMARC Identifier alignment test” (and the same for SPF), plus the disposition applied. auth_results “contains DKIM and SPF results, uninterpreted with respect to DMARC.”

What does the parser look like?

import gzip, os, re, sys, zipfile
import xml.etree.ElementTree as ET
from collections import Counter
from datetime import datetime, timezone

MAX_BYTES = 50_000_000  # refuse anything that inflates past 50 MB

def load(path):
    with open(path, 'rb') as f:
        head = f.read(4)
    if head[:2] == b'\x1f\x8b':                       # gzip
        with gzip.open(path) as f:
            data = f.read(MAX_BYTES + 1)
    elif head == b'PK\x03\x04':                       # zip
        with zipfile.ZipFile(path) as z, z.open(z.namelist()[0]) as f:
            data = f.read(MAX_BYTES + 1)
    else:
        with open(path, 'rb') as f:
            data = f.read(MAX_BYTES + 1)
    if len(data) > MAX_BYTES:
        raise ValueError('report too large')
    if b'<!DOCTYPE' in data:                          # a report has no use for one
        raise ValueError('DOCTYPE refused')
    data = re.sub(rb'</?xs:schema[^<>]*>', b'', data) # stray wrapper, seen in one sample
    root = ET.fromstring(data)
    for el in root.iter():                            # drop any {namespace}
        el.tag = el.tag.rpartition('}')[2]
    return root

def text(el, path):
    found = el.find(path)
    if found is None or not (found.text or '').strip():
        return '-'
    return found.text.strip()

def day(ts):
    return datetime.fromtimestamp(int(ts), timezone.utc).strftime('%Y-%m-%d %H:%M')

def raw(rec, kind):
    return ' '.join(f"{text(r, 'domain')}={text(r, 'result')}"
                    for r in rec.findall(f'auth_results/{kind}')) or '-'

for path in sys.argv[1:]:
    try:
        root = load(path)
    except (ET.ParseError, ValueError, OSError, zipfile.BadZipFile) as e:
        print(f'\n{os.path.basename(path)}\n  SKIPPED: {e}')
        continue
    print(f"\n{text(root, 'report_metadata/org_name')} about "
          f"{text(root, 'policy_published/domain')} (p={text(root, 'policy_published/p')}), "
          f"{day(text(root, 'report_metadata/date_range/begin'))} to "
          f"{day(text(root, 'report_metadata/date_range/end'))} UTC")
    rows = Counter()
    for rec in root.iter('record'):
        pe = 'row/policy_evaluated/'
        key = (text(rec, 'row/source_ip'), text(rec, 'identifiers/header_from'),
               text(rec, pe + 'disposition'), text(rec, pe + 'dkim'), text(rec, pe + 'spf'),
               raw(rec, 'dkim'), raw(rec, 'spf'))
        rows[key] += int(text(rec, 'row/count'))
    print(f"  {'source_ip':<16}{'count':>6}  {'from':<12}{'disp':<8}{'dkim':<5}{'spf':<5} raw dkim | raw spf")
    for (ip, frm, disp, dkim, spf, rdkim, rspf), n in rows.most_common(5):
        print(f'  {ip:<16}{n:>6}  {frm:<12}{disp:<8}{dkim:<5}{spf:<5} {rdkim} | {rspf}')
    if len(rows) > 5:
        print(f'  ... {len(rows) - 5} more rows')
    passed = sum(n for k, n in rows.items() if 'pass' in (k[3], k[4]))
    print(f'  {sum(rows.values())} messages, {passed} passed DMARC')

It picks gzip, zip or plain XML from the first bytes, not the extension. The draft says a row covers one IP “for the particular combination of the policy evaluated,” so one IP can appear in several records, and we sum identical rows. None of our samples repeated one.

What did it print on the sample reports?

We ran python3 -I dmarc_table.py on nine sample files, including gzipped, zipped, namespaced, very large and broken ones.

Outlook.com about example.com (p=none), 2024-03-30 00:00 to 2024-03-31 00:00 UTC
  source_ip        count  from        disp    dkim spf   raw dkim | raw spf
  100.24.188.149       1  example.com none    fail fail  - | example.com=fail
  1 messages, 0 passed DMARC

FastMail Pty Ltd about indemed.com (p=none), 2018-01-16 00:00 to 2018-01-16 23:59 UTC
  source_ip        count  from        disp    dkim spf   raw dkim | raw spf
  104.195.80.20        1  example.com none    fail fail  - | example.com=softfail
  1 messages, 0 passed DMARC

XYZ Corporation about example.com (p=none), 2018-09-13 15:41 to 2018-09-14 15:41 UTC
  source_ip        count  from        disp    dkim spf   raw dkim | raw spf
  148.243.137.254      1  example.com none    fail fail  - | -
  1 messages, 0 passed DMARC

addisonfoods.com about example.com (p=none), 2018-09-05 00:00 to 2018-09-05 23:59 UTC
  source_ip        count  from        disp    dkim spf   raw dkim | raw spf
  109.203.100.17       1  example.com none    fail fail  toptierhighticket.club=pass | -
  1 messages, 0 passed DMARC

example.org about example.com (p=quarantine), 2024-01-25 05:12 to 2024-01-25 12:28 UTC
  source_ip        count  from        disp    dkim spf   raw dkim | raw spf
  198.51.100.123       2  example.com none    pass fail  example.com=pass | example.edu=pass
  2 messages, 2 passed DMARC

ikea.com about example.de (p=none), 2018-10-04 22:00 to 2018-10-05 22:00 UTC
  source_ip        count  from        disp    dkim spf   raw dkim | raw spf
  234.234.234.234      1  example.de  none    fail fail  example.de=pass | mailrelay.com=none
  1 messages, 0 passed DMARC

Sample Reporter about example.com (p=quarantine), 1979-08-07 00:00 to 1979-08-07 23:59 UTC
  source_ip        count  from        disp    dkim spf   raw dkim | raw spf
  192.0.2.123        123  example.com pass    pass fail  example.com=pass | example.com=fail
  123 messages, 123 passed DMARC

- about example.com (p=none), 2024-03-31 15:00 to 2024-04-01 15:00 UTC
  source_ip        count  from        disp    dkim spf   raw dkim | raw spf
  12.20.121.1          1  example.com none    fail fail  - | -=none
  12.20.121.2          1  example.com none    fail fail  - | -=none
  12.20.121.3          1  example.com none    fail fail  - | -=none
  12.20.121.4          1  example.com none    fail fail  - | -=none
  12.20.121.5          1  example.com none    fail fail  - | -=none
  ... 2281 more rows
  2286 messages, 0 passed DMARC

invalid_xml.xml
  SKIPPED: not well-formed (invalid token): line 5, column 17

After the IP, count and From domain come what the receiver did (disp), the aligned DKIM and SPF verdicts, and the raw results as domain=result. A row passes DMARC when either aligned verdict is pass, the rule our November 10 article describes.

How do you read policy_evaluated against auth_results?

SampleAligned verdictRaw resultsWhat it suggests
example.orgDKIM pass, SPF failDKIM example.com=pass, SPF example.edu=passPasses through DKIM. SPF passed for another domain.
addisonfoods.comboth failDKIM toptierhighticket.club=passSomeone else’s valid signature.
Outlook.com, FastMailboth failSPF example.com=fail or softfailNot in your SPF record, no signature.
the 2,286-row sampleboth failSPF domain empty, noneNothing at all, from 2,286 addresses.
ikea.comboth failDKIM example.de=passA raw pass, yet a failing verdict.

The example.org row is the healthy shape for a third-party service. Its own bounce domain passes SPF without aligning. The DKIM signature is for example.com, so DMARC passes and nothing is quarantined.

The ikea.com row is odd. The sample is anonymized, so the original signing domain may have differed. Report the receiver’s verdict and use the raw results to explain it, rather than recomputing DMARC yourself. That row’s SPF scope is also helo, though the draft says “the only valid value for the ‘scope’ element is ‘mfrom’.”

Which rows mean a forgotten sender, and which mean spoofing?

A forgotten sender looks like the addisonfoods.com row: a raw pass for a domain belonging to some service. Newsletter, invoicing and booking tools sign with their own domain until you add DKIM records for yours. Look up who owns the IP. If it is a tool you use, fix that tool’s domain settings.

Spoofing looks like the 2,286-row sample: many unfamiliar addresses, one message each, nothing passing even for another domain. It is a test file, so we cannot say what sent it, but it is the shape to watch for. At p=none those messages were delivered.

The Outlook.com and FastMail rows sit between: one message failing SPF for your own domain. Watch whether it recurs.

The draft also warns that “the data contained within aggregate reports may be forged.” Anyone can email XML to your rua address.

What tripped us up?

First, namespaces. The newer sample declares xmlns="urn:ietf:params:xml:ns:dmarc-2.0", the namespace in the draft’s schema. ElementTree then prefixes every tag. Printing root.tag and root.find('report_metadata/org_name') on that file gave:

{urn:ietf:params:xml:ns:dmarc-2.0}feedback
None

Stripping the {...} prefix after parsing fixes it. The rest:

  • A stray schema tag. The ikea.com sample opens an <xs:schema> tag and never closes it. ElementTree failed with no element found: line 47, column 11 until we added parsedmarc’s re.sub pattern.
  • Broken XML. invalid_xml.xml contains <email><bad-xml@bad-xml.net></email>. parsedmarc retries such files with lxml’s recovery mode. We skip them.
  • Zip as well as gzip. The draft lists only .xml and .xml.gz, but one sample is a .zip, as is the attachment in a 2019 sample email from Google.
  • Empty elements. Empty <org_name>, <domain>, <auth_results> and <reason> elements all appear. text() returns - instead of failing on None.
  • Timestamps. Outlook.com’s report runs midnight to midnight UTC, ikea.com’s 22:00 to 22:00. Do not assume a calendar day.
  • A fourth disposition. The namespaced sample says pass. The draft’s schema adds it beside none, quarantine and reject, as “No action, passing DMARC w/enforcing policy.”

Should you parse untrusted XML with ElementTree?

Carefully. The draft warns that “the archive decompressor and XML parser are at risk to resource exhaustion attacks (zip bomb or XML bomb).” The defusedxml project adds: “With just a few hundred Bytes of XML data an attacker can occupy several Gigabytes of memory within seconds.”

We built a 238-byte file with three levels of nested entities and a 58 KB gzip file that inflates to 60 MB of spaces. The parser refused both:

entities.xml
  SKIPPED: DOCTYPE refused

zeros.xml.gz
  SKIPPED: report too large

Here is the same entity file through plain ElementTree and through defusedxml:

import sys
import xml.etree.ElementTree as ET
import defusedxml.ElementTree as DET

data = open(sys.argv[1], 'rb').read()
print('ElementTree:', len(ET.fromstring(data).find('report_metadata/org_name').text), 'characters')
try:
    DET.fromstring(data)
except Exception as e:
    print('defusedxml: ', type(e).__name__, e)
ElementTree: 1000 characters
defusedxml:  EntitiesForbidden EntitiesForbidden(name='a', system_id=None, public_id=None)

ElementTree expanded it to 1,000 characters, and each extra level would multiply that by ten. Our parser refuses any DOCTYPE instead, as parsedmarc does. If a package is fine for you, defusedxml.ElementTree.fromstring can replace the parse call. Keep the size cap either way: defusedxml guards the parser, not the decompression in front of it.

Sources

  • DMARC Working Group, draft-ietf-dmarc-aggregate-reporting source, draft 32 (March 17, 2025) and its XSD, read November 12, 2026. Report structure, field meanings, compression, file names and security warnings.
  • domainaware, parsedmarc, release 11.3.0, Apache License 2.0, read November 12, 2026. Sample reports, the RFC 9990 mention, and its xs:schema and DOCTYPE handling.
  • defusedxml on PyPI, version 0.7.1, read November 12, 2026. The XML bomb quote.

Limitations

  • None of these rows come from our own domains, and the samples are partly anonymized.
  • We could not open RFC 7489 or RFC 9990. Draft 32 may differ from the published text.
  • The parser reads only the first file in a zip and does not open report emails.
  • We did not test IPv6 sources or extension elements.
  • It does not look up who owns each IP, which is what separates a forgotten sender from spoofing.

Frequently asked questions

What is a DMARC aggregate report?

It is an XML file a receiving mail service sends to the address in your DMARC record's rua tag, covering a reporting period; each sample we ran covered about a day. It lists each IP address that sent mail with your domain in the From line, how many messages it sent, and how they did on SPF, DKIM and DMARC. It holds counts and results, not the messages themselves.

What is the difference between policy_evaluated and auth_results?

policy_evaluated is the receiver's DMARC verdict: whether DKIM and SPF passed in alignment with your From domain, and what it did with the mail. auth_results lists the raw SPF and DKIM results for whatever domains were checked, without the DMARC interpretation. A row can show a DKIM pass in auth_results and still fail in policy_evaluated when the signing domain is someone else's.

How do I tell a forgotten sender from spoofing in a DMARC report?

A forgotten sender usually shows a raw SPF or DKIM pass for a service's own domain, from IP addresses that belong to a tool you use. Spoofing usually shows nothing passing at all, from addresses you do not recognize. The report alone cannot prove which it is, so look up who owns the IP address and compare it with your list of sending services.

Why does my DMARC report arrive as a .zip or .gz file?

The DMARC working group's reporting draft says the XML should be compressed with gzip, and names the file after the receiver, your domain and the start and end timestamps. Some providers send zip files instead. Among the samples we tested, one report was gzipped, one was zipped, and a sample report email from Google carried a .zip attachment.

Is it safe to parse DMARC reports with Python's ElementTree?

Treat every report as untrusted input, because anyone can send XML to your rua address. The working group's draft names zip bombs and XML bombs as risks to report processors. We cap the decompressed size and refuse any file with a DOCTYPE. The defusedxml package is a tested alternative that rejects entity declarations outright.

More from Research

← All research