An automated, zero-cost pipeline built with Google Apps Script and Gmail that automatically parses incoming DMARC Aggregate Reports (.xml, .xml.gz, .zip), resolves sending provider organizations via reverse IP lookups, and sends a digest email summarizing SPF and DKIM authentication pass/fail rates.
- Automatic Attachment Extraction: Handles
.xml,.gz, and.zipreport formats directly inside Gmail. - IP Provider Lookup: Performs dynamic API queries (
ipinfo.io) to identify sending organizations (e.g., Google Cloud, AWS, Mailchimp) for failed authentication attempts. - Zero Infrastructure Cost: Runs entirely within Google Apps Script and Gmail without needing external servers or paid services.
- Scheduled Digest: Automatically delivers a clean, formatted HTML email digest on a schedule you control.
- Automatic Thread Management: Strips Gmail labels after processing so old reports are never recounted.
- In Gmail, navigate to Settings > Filters and Blocked Addresses > Create a new filter.
- Under Has attachment, check the box.
- In Includes the words, enter:
filename:xml OR filename:gz OR filename:zip - This will typically match on subject lines like "Report domain:" which most mailbox providers use for DMARC aggregate reports β narrow the filter further with a From or Subject condition if you get false positives.
- Click Create filter, then check Apply the label and choose (or create) a label named
DMARC-Report. This label is what the script looks for, so the name must match exactly.
- Go to script.google.com and create a New project.
- Delete the default boilerplate code and paste in the contents of
Code.gsfrom this repo. - Rename the project (top left) to something like
DMARC Report Parser. - Click Save.
- In the Apps Script editor, select the
processDmarcReportsfunction from the function dropdown and click Run. - Google will prompt you to authorize the script β it needs access to Gmail (to read/label messages and send the summary email) and external requests (to look up sending IPs via ipinfo.io).
- Approve the permissions. The first run will process whatever is currently under the
DMARC-Reportlabel.
- In the Apps Script editor, click the clock icon (Triggers) in the left sidebar.
- Click Add Trigger.
- Configure it as:
- Function to run:
processDmarcReports - Event source:
Time-driven - Type of time based trigger:
Day timer(orHour timerif you want it more frequent) - Time of day: whatever works for you
- Function to run:
- Save. The script will now run automatically and email you a digest whenever it finds new reports.
Each run produces an HTML email summarizing:
- Total DMARC-reported email volume processed
- Pass / fail counts and pass rate for SPF + DKIM alignment
- A breakdown of failing source IPs with their resolved provider/organization, so you can quickly spot unauthorized or misconfigured senders
LABEL_NAMEinCode.gscontrols which Gmail label the script watches β change it if you used a different label name.- The script pulls up to 25 threads per run (
label.getThreads(0, 25)); increase this if you expect a high volume of reports. - Recipient defaults to the account running the script (
Session.getActiveUser().getEmail()). Change this if you want the digest sent elsewhere. - IP-to-organization lookups use the free tier of ipinfo.io, which has rate limits β for heavy volume, consider adding an API token.
This script processes report data already delivered to your inbox and does not transmit any data outside of Google's infrastructure and the public ipinfo.io lookup API. Review and test in your own environment before relying on it for security monitoring.