Weekly Mailgun sending domain and DKIM health check

By General Input

Check every Mailgun sending domain each Monday, log the results to a spreadsheet, and get a Slack alert only when something is actually broken.

Integrations

  • Mailgun
  • Google Sheets
  • Slack Bot

Type

Deterministic Code

Categories

  • Engineering
  • Operations

Every Monday at 7am, run a health check across all of my Mailgun sending domains so that a broken DNS record never silently kills our email.

Start by calling Mailgun List Domains to enumerate every domain on the account. Follow the pagination links until you have collected the complete list rather than just the first page, so newly added domains are always included without me maintaining a list by hand.

For each domain, call Mailgun Verify Domain to re-check its DNS records, and call Mailgun List DKIM Keys for a Domain to confirm the domain still has an active DKIM key. Read the verification state from the Verify Domain response and the DKIM status from the key list, treating a domain with no active key as a failure. Also capture which specific DNS records came back invalid or missing, since that is what makes the alert actionable.

Append one row per domain per week to a Google Sheets log using Append Values. Each row should capture the run date, the domain name, its verification state, and its DKIM status, so we build an audit trail over time and can see exactly when a domain stopped being healthy.

If any domain comes back unverified or is missing an active DKIM key, post a single alert to our #infra Slack channel using Slack Bot Send a Message. The alert should list exactly which domains failed and which records need fixing, grouped by domain so it is easy to act on. Send one consolidated message per run rather than one message per failing domain.

When every domain passes, do not post anything to Slack. The spreadsheet row is still written on healthy weeks, but the channel stays silent so that an alert always means something real needs attention.

Two implementation notes. Mailgun is region-scoped: EU accounts must call api.eu.mailgun.net instead of api.mailgun.net, and a domain only works against the region it was created in, so make the region straightforward to configure. Also handle errors per domain rather than aborting the whole run, so one domain that errors still lets the rest be checked, logged, and reported.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentLocal listing health board for every location you manageLet support send one-off Loops emails without an engineerA brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensStop cold emails to anyone with a live deal in PipedriveLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasoniMessage campaign console with pre-flight checks and delivery board