{
  "name": "Cold email sending domain health check (SPF, DKIM, DMARC, MX) with Google Sheets",
  "nodes": [
    {
      "id": "3cc10ba3-65fe-456d-a6d8-1b39e9b956b7",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -760,
        -260
      ],
      "parameters": {
        "content": "## Cold email sending domain health check\n\n### How it works\nReads your sending domains from Google Sheets, then looks up SPF, DMARC, MX and DKIM through Google's free public DNS over HTTPS API (no key needed). Each domain gets a score out of 100 (SPF 30, DMARC 30, DKIM 25, MX 15) plus a plain English list of issues. Results are written back to the same sheet, and if any domain scores below your pass mark you get one summary email listing what to fix. It runs every Monday at 08:00 or whenever you press Test workflow.\n\n### Setup\n1. Create a Google Sheet with a tab called **Domains** and these headers: domain, dkim_selector, spf_status, spf_record, dmarc_status, dmarc_policy, dkim_status, mx_status, score, result, issues, checked_at\n2. Fill in the **domain** column. **dkim_selector** is optional per row.\n3. Open **Set your settings** and add your spreadsheet ID, default DKIM selector (for example google or selector1), alert email and pass score.\n4. Connect Google Sheets and Gmail credentials in the two Sheets nodes and the Gmail node.\n\n### Customization\nChange the weights in **Score each domain**, swap Gmail for Slack, or change the schedule.\n\nChecks are DNS only. They do not test blacklists or inbox placement.\n\nBuilt by Extol Affiliates (extol.si). Related benchmark: https://www.extol.si/insights-cold-email-benchmark-uk.html",
        "width": 520,
        "height": 860
      }
    },
    {
      "id": "1fe64781-f4d1-461b-a611-a5e79e3124dd",
      "name": "Section: settings",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -200,
        -260
      ],
      "parameters": {
        "content": "## 1. Trigger and settings\nAll values you need to change live in one node.",
        "width": 440,
        "height": 520,
        "color": 7
      }
    },
    {
      "id": "ed32dbcf-be90-4566-a84d-011069aeed0a",
      "name": "Section: lookups",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        280,
        -260
      ],
      "parameters": {
        "content": "## 2. Read domains and query DNS\nEach domain becomes four lookups against dns.google. Failed lookups are kept and reported, not dropped.",
        "width": 680,
        "height": 520,
        "color": 7
      }
    },
    {
      "id": "10c1918e-b672-47c6-a5ec-feca1073dfaf",
      "name": "Section: results",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1000,
        -260
      ],
      "parameters": {
        "content": "## 3. Score, save and alert\nScores are written back to the Domains tab. An email only goes out when at least one domain fails.",
        "width": 900,
        "height": 680,
        "color": 7
      }
    },
    {
      "id": "ff596b22-ad44-446e-a9f4-99b3b336856d",
      "name": "Run check now",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -140,
        -40
      ],
      "parameters": {}
    },
    {
      "id": "850ab7ea-990f-4421-a5ca-d95a294b7202",
      "name": "Every Monday at 08:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -140,
        140
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 8
            }
          ]
        }
      }
    },
    {
      "id": "f8be1f6e-61e2-42f9-ad05-df4855e9bf71",
      "name": "Set your settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        80,
        60
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "69bbab07-04fd-4211-ae7c-5ba01fdb948d",
              "name": "spreadsheetId",
              "value": "PASTE_YOUR_GOOGLE_SHEET_ID",
              "type": "string"
            },
            {
              "id": "b940e6d3-cf69-44f4-acaf-30844ea39e4d",
              "name": "domainsTab",
              "value": "Domains",
              "type": "string"
            },
            {
              "id": "0763820b-eed2-4c61-a963-712b5c90be27",
              "name": "dkimSelector",
              "value": "google",
              "type": "string"
            },
            {
              "id": "2fc6258b-f065-488b-a0fc-e8718e2d22f9",
              "name": "alertEmail",
              "value": "you@example.com",
              "type": "string"
            },
            {
              "id": "b67976a9-3c45-4ca9-a5cc-8e169523c1a0",
              "name": "passScore",
              "value": 80,
              "type": "number"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "297a6978-20c3-4769-a047-be928d0902f3",
      "name": "Read sending domains",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        340,
        60
      ],
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "value": "={{ $('Set your settings').first().json.spreadsheetId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('Set your settings').first().json.domainsTab }}",
          "mode": "name"
        },
        "options": {}
      }
    },
    {
      "id": "63b9d626-b8ca-4579-a9fe-60ae2586c722",
      "name": "Build DNS queries",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        60
      ],
      "parameters": {
        "jsCode": "// Turns each sheet row into four DNS lookups (SPF, DMARC, MX, DKIM).\n// Expected sheet columns: domain (required), dkim_selector (optional).\nconst settings = $('Set your settings').first().json;\nconst defaultSelector = String(settings.dkimSelector || '').trim();\n\nconst cleanDomain = (value) => String(value || '')\n  .trim()\n  .toLowerCase()\n  .replace(/^[a-z]+:\\/\\//, '')\n  .replace(/^www\\./, '')\n  .split(/[\\/?#:@\\s]/)[0]\n  .replace(/\\.$/, '');\n\nconst seen = new Set();\nconst out = [];\nfor (const item of $input.all()) {\n  const domain = cleanDomain(item.json.domain);\n  if (!domain || !domain.includes('.') || seen.has(domain)) continue;\n  seen.add(domain);\n  const selector = String(item.json.dkim_selector || defaultSelector).trim();\n  const lookups = [\n    { check: 'spf', name: domain, type: 'TXT' },\n    { check: 'dmarc', name: `_dmarc.${domain}`, type: 'TXT' },\n    { check: 'mx', name: domain, type: 'MX' },\n  ];\n  if (selector) lookups.push({ check: 'dkim', name: `${selector}._domainkey.${domain}`, type: 'TXT' });\n  for (const l of lookups) {\n    out.push({ json: { domain, selector, ...l } });\n  }\n}\nreturn out;"
      }
    },
    {
      "id": "e83523da-8179-4805-a74b-a2c0260fe0e0",
      "name": "Query Google public DNS",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        780,
        60
      ],
      "parameters": {
        "url": "https://dns.google/resolve",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "={{ $json.name }}"
            },
            {
              "name": "type",
              "value": "={{ $json.type }}"
            }
          ]
        },
        "options": {
          "batching": {
            "batch": {
              "batchSize": 10,
              "batchInterval": 250
            }
          },
          "response": {
            "response": {
              "responseFormat": "json"
            }
          },
          "timeout": 10000
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 1000,
      "onError": "continueRegularOutput"
    },
    {
      "id": "959fcaf7-4f40-480d-af24-1825f499ba6b",
      "name": "Score each domain",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1060,
        60
      ],
      "parameters": {
        "jsCode": "// Pairs each DNS answer with its lookup, then scores every domain out of 100.\n// Weights: SPF 30, DMARC 30, DKIM 25, MX 15. Adjust them here if you like.\nconst settings = $('Set your settings').first().json;\nconst passScore = Number(settings.passScore) || 80;\nconst lookups = $('Build DNS queries').all();\nconst answers = $input.all();\n\nconst txtValues = (res, wantedType) => {\n  const answer = (res && Array.isArray(res.Answer)) ? res.Answer : [];\n  return answer\n    .filter((a) => a.type === wantedType)\n    .map((a) => String(a.data || '').replace(/\"\\s*\"/g, '').replace(/^\"|\"$/g, '').trim());\n};\n\nconst domains = {};\nlookups.forEach((lookup, i) => {\n  const { domain, selector, check } = lookup.json;\n  const res = answers[i] ? answers[i].json : {};\n  if (!domains[domain]) domains[domain] = { domain, selector, raw: {} };\n  domains[domain].raw[check] = res;\n});\n\nconst now = new Date().toISOString();\nconst results = Object.values(domains).map((d) => {\n  const issues = [];\n  let score = 0;\n\n  // SPF\n  const spfRecords = txtValues(d.raw.spf, 16).filter((t) => /^v=spf1(\\s|$)/i.test(t));\n  let spfStatus = 'missing';\n  if (d.raw.spf && d.raw.spf.error) { spfStatus = 'lookup error'; issues.push('SPF lookup failed'); }\n  else if (spfRecords.length > 1) { spfStatus = 'multiple records'; issues.push('More than one SPF record (receivers treat this as a permanent error)'); }\n  else if (spfRecords.length === 1) {\n    const spf = spfRecords[0].toLowerCase();\n    const lookupTerms = spf.split(/\\s+/)\n      .map((t) => t.replace(/^[+\\-~?]/, ''))\n      .filter((t) => /^(include:|a$|a:|a\\/|mx$|mx:|mx\\/|ptr|exists:|redirect=)/.test(t)).length;\n    if (/[-~]all\\b/.test(spf)) { spfStatus = 'ok'; score += 30; }\n    else if (/redirect=/.test(spf)) { spfStatus = 'ok (redirect)'; score += 30; }\n    else { spfStatus = 'weak'; score += 15; issues.push('SPF does not end in -all or ~all'); }\n    if (lookupTerms > 10) issues.push(`SPF has ${lookupTerms} DNS lookup terms at the top level (limit is 10)`);\n  } else { issues.push('No SPF record'); }\n\n  // DMARC\n  const dmarcRecords = txtValues(d.raw.dmarc, 16).filter((t) => /^v=DMARC1/i.test(t));\n  let dmarcStatus = 'missing';\n  let dmarcPolicy = '';\n  if (d.raw.dmarc && d.raw.dmarc.error) { dmarcStatus = 'lookup error'; issues.push('DMARC lookup failed'); }\n  else if (dmarcRecords.length > 1) { dmarcStatus = 'multiple records'; issues.push('More than one DMARC record'); }\n  else if (dmarcRecords.length === 1) {\n    const rec = dmarcRecords[0];\n    const p = (rec.match(/(?:^|;)\\s*p\\s*=\\s*([a-z]+)/i) || [])[1];\n    dmarcPolicy = p ? p.toLowerCase() : '';\n    if (dmarcPolicy === 'reject' || dmarcPolicy === 'quarantine') { dmarcStatus = 'ok'; score += 30; }\n    else if (dmarcPolicy === 'none') { dmarcStatus = 'monitoring only'; score += 20; issues.push('DMARC policy is p=none'); }\n    else { dmarcStatus = 'invalid'; issues.push('DMARC record has no valid p= tag'); }\n    if (!/rua\\s*=/i.test(rec)) issues.push('DMARC has no rua reporting address');\n  } else { issues.push('No DMARC record'); }\n\n  // MX\n  const mxRecords = d.raw.mx && Array.isArray(d.raw.mx.Answer) ? d.raw.mx.Answer.filter((a) => a.type === 15) : [];\n  let mxStatus = 'missing';\n  if (d.raw.mx && d.raw.mx.error) { mxStatus = 'lookup error'; issues.push('MX lookup failed'); }\n  else if (mxRecords.length) { mxStatus = 'ok'; score += 15; }\n  else { issues.push('No MX record, so replies and bounces have nowhere to go'); }\n\n  // DKIM\n  let dkimStatus = 'not checked';\n  if (!d.selector) { issues.push('No DKIM selector set, DKIM not checked'); }\n  else if (d.raw.dkim && d.raw.dkim.error) { dkimStatus = 'lookup error'; issues.push('DKIM lookup failed'); }\n  else {\n    const dkimRecords = txtValues(d.raw.dkim, 16);\n    const valid = dkimRecords.find((t) => /(^|;)\\s*p\\s*=\\s*[A-Za-z0-9+\\/=]{20,}/.test(t));\n    if (valid) { dkimStatus = 'ok'; score += 25; }\n    else if (dkimRecords.length) { dkimStatus = 'invalid or revoked'; issues.push(`DKIM record for selector \"${d.selector}\" has no public key`); }\n    else { dkimStatus = 'missing'; issues.push(`No DKIM record for selector \"${d.selector}\"`); }\n  }\n\n  return {\n    json: {\n      domain: d.domain,\n      dkim_selector: d.selector,\n      spf_status: spfStatus,\n      spf_record: spfRecords.join(' | '),\n      dmarc_status: dmarcStatus,\n      dmarc_policy: dmarcPolicy,\n      dkim_status: dkimStatus,\n      mx_status: mxStatus,\n      score,\n      result: score >= passScore ? 'pass' : 'fail',\n      issues: issues.join('; '),\n      checked_at: now,\n    },\n  };\n});\nreturn results;"
      }
    },
    {
      "id": "fba20944-ca1c-4ad1-ac94-383931376d48",
      "name": "Write results to sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1280,
        60
      ],
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "={{ $('Set your settings').first().json.spreadsheetId }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ $('Set your settings').first().json.domainsTab }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [
            "domain"
          ],
          "schema": [
            {
              "id": "domain",
              "displayName": "domain",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "dkim_selector",
              "displayName": "dkim_selector",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "spf_status",
              "displayName": "spf_status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "spf_record",
              "displayName": "spf_record",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "dmarc_status",
              "displayName": "dmarc_status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "dmarc_policy",
              "displayName": "dmarc_policy",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "dkim_status",
              "displayName": "dkim_status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "mx_status",
              "displayName": "mx_status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "score",
              "displayName": "score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "result",
              "displayName": "result",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "issues",
              "displayName": "issues",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "checked_at",
              "displayName": "checked_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "60dfe122-2ad0-4a19-af14-517fdbed80c8",
      "name": "Build failing summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1500,
        60
      ],
      "parameters": {
        "jsCode": "// Builds one summary item. The IF node after this only emails when something failed.\nconst scored = $('Score each domain').all().map((i) => i.json);\nconst failing = scored.filter((d) => d.result === 'fail');\nconst lines = failing.map((d) => `- ${d.domain}: score ${d.score}/100. ${d.issues || 'No detail'}`);\nconst body = failing.length\n  ? `${failing.length} of ${scored.length} sending domains are below the pass score.\\n\\n${lines.join('\\n')}\\n\\nFull results are in your Google Sheet.`\n  : `All ${scored.length} sending domains passed.`;\nreturn [{\n  json: {\n    checked: scored.length,\n    failingCount: failing.length,\n    subject: `Sending domain health: ${failing.length} of ${scored.length} need attention`,\n    body,\n  },\n}];"
      }
    },
    {
      "id": "d1cb7690-b6a6-444e-ae07-25d26b05bc2d",
      "name": "Any failing domains?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1700,
        60
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "42412b69-7a9b-4ab4-a926-7ac7091cb23e",
              "leftValue": "={{ $json.failingCount }}",
              "rightValue": 0,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "bb712901-639b-45cc-a6ac-bb7afbfc27d4",
      "name": "Email failing domains",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1700,
        300
      ],
      "parameters": {
        "sendTo": "={{ $('Set your settings').first().json.alertEmail }}",
        "subject": "={{ $json.subject }}",
        "emailType": "text",
        "message": "={{ $json.body }}",
        "options": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "Run check now": {
      "main": [
        [
          {
            "node": "Set your settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every Monday at 08:00": {
      "main": [
        [
          {
            "node": "Set your settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set your settings": {
      "main": [
        [
          {
            "node": "Read sending domains",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read sending domains": {
      "main": [
        [
          {
            "node": "Build DNS queries",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build DNS queries": {
      "main": [
        [
          {
            "node": "Query Google public DNS",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Query Google public DNS": {
      "main": [
        [
          {
            "node": "Score each domain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score each domain": {
      "main": [
        [
          {
            "node": "Write results to sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write results to sheet": {
      "main": [
        [
          {
            "node": "Build failing summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build failing summary": {
      "main": [
        [
          {
            "node": "Any failing domains?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Any failing domains?": {
      "main": [
        [
          {
            "node": "Email failing domains",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
