{
  "id": "ChyUpdqplMMK9goy",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "dmarc",
  "tags": [],
  "nodes": [
    {
      "id": "20c68419-20da-4d03-bdbb-ef724420814d",
      "name": "unzip",
      "type": "n8n-nodes-base.compression",
      "position": [
        32,
        -768
      ],
      "parameters": {
        "binaryPropertyName": "attachment_0"
      },
      "typeVersion": 1.1
    },
    {
      "id": "279e9ea7-0c62-41dd-8275-4db569b5e30d",
      "name": "xml",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        256,
        -768
      ],
      "parameters": {
        "options": {},
        "operation": "xml",
        "binaryPropertyName": "file_0"
      },
      "typeVersion": 1
    },
    {
      "id": "01b3cacd-ea7d-4a83-9514-6dc885e58f61",
      "name": "xml2json",
      "type": "n8n-nodes-base.xml",
      "position": [
        480,
        -768
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "132c9c80-b18b-4b25-9b17-0c1bbfdd3df4",
      "name": "set",
      "type": "n8n-nodes-base.set",
      "position": [
        704,
        -768
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "3c2dc439-7fb0-4329-b911-d10d279c9595",
              "name": "table",
              "type": "string",
              "value": "=<table border=\"1\" cellpadding=\"4\" cellspacing=\"0\" style=\"width:100%; max-width:760px; border-collapse:collapse; margin:12px 0;\">\n<tr>\n    <th colspan=\"4\" align=\"left\" style=\"text-align:left; padding:6px 8px;\">\n      <strong>{{$json[\"feedback\"][\"report_metadata\"][\"org_name\"]}}</strong> \u2192 \n      {{$json[\"feedback\"][\"policy_published\"][\"domain\"]}}\n      <code style=\"white-space:normal; word-break:break-all; font-family:Courier, monospace; margin-left:4px;\">\n        [v=DMARC1; p={{$json[\"feedback\"][\"policy_published\"][\"p\"]}};]\n      </code>\n    </th>\n  </tr>\n  \n  <!-- Records header -->\n<tr>\n  <th align=\"left\" style=\"text-align:left;\">IP</th>\n  <th align=\"left\" style=\"text-align:left;\">Count</th>\n  <th align=\"left\" style=\"text-align:left;\">DKIM</th>\n  <th align=\"left\" style=\"text-align:left;\">SPF</th>\n</tr>\n\n  <!-- Records rows -->\n  {{\n    Array.isArray($json[\"feedback\"][\"record\"])\n      ? $json[\"feedback\"][\"record\"].map(r => `\n        <tr>\n          <td><code>${r.row.source_ip}</code></td>\n          <td style=\"text-align:right;\">${r.row.count}</td>\n          <td style=\"text-align:left;\">${r.row.policy_evaluated.dkim}</td>\n          <td style=\"text-align:left;\">${r.row.policy_evaluated.spf}</td>\n        </tr>\n      `).join('')\n      : `<tr>\n          <td><code>${$json[\"feedback\"][\"record\"][\"row\"][\"source_ip\"]}</code></td>\n          <td style=\"text-align:left;\">${$json[\"feedback\"][\"record\"][\"row\"][\"count\"]}</td>\n          <td style=\"text-align:left;\">${$json[\"feedback\"][\"record\"][\"row\"][\"policy_evaluated\"][\"dkim\"]}</td>\n          <td style=\"text-align:left;\">${$json[\"feedback\"][\"record\"][\"row\"][\"policy_evaluated\"][\"spf\"]}</td>\n        </tr>`\n  }}\n</table>\n"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1d46956f-93c6-402d-9ae1-df4636920b18",
      "name": "send",
      "type": "n8n-nodes-base.gmail",
      "position": [
        928,
        -768
      ],
      "parameters": {
        "sendTo": "user@example.com",
        "message": "={{ $json.table }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "={{ $('xml2json').item.json.feedback.report_metadata.org_name }} DMARC Report for {{ $('xml2json').item.json.feedback.policy_published.domain }}"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "d4e0902d-a50f-46aa-a800-e342aabe3358",
      "name": "cron",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -416,
        -768
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 13
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "8f154531-edde-43fd-8547-94ece2527a2b",
      "name": "dmarc",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -192,
        -768
      ],
      "parameters": {
        "limit": 5,
        "simple": false,
        "filters": {
          "q": "from:(user@example.com OR user@example.com) in:anywhere",
          "receivedAfter": "={{ $now - 24 * 60 * 60 * 1000 }}"
        },
        "options": {
          "downloadAttachments": true
        },
        "operation": "getAll"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "4a12a76b-3924-43d6-ab5b-c602a9fb4fe0",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        -864
      ],
      "parameters": {
        "width": 288,
        "content": "Send report by email. \n\nSuggestion: You could add an Airtable node here if you want to keep records."
      },
      "typeVersion": 1
    },
    {
      "id": "219325bb-86f9-44d7-be9a-a25ddca52775",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        208,
        -864
      ],
      "parameters": {
        "width": 544,
        "content": "Convert the XML to JSON. \nHandle both zip and gz formats.\nCreate HTML table for email."
      },
      "typeVersion": 1
    },
    {
      "id": "d8218575-9846-436c-b429-4a33a6f3d721",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -208,
        -864
      ],
      "parameters": {
        "width": 368,
        "content": "Get DMARC reports and download the attached reports."
      },
      "typeVersion": 1
    },
    {
      "id": "9b8f2ae9-f804-4d02-bc33-1a9e43611e06",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -592,
        -864
      ],
      "parameters": {
        "width": 368,
        "height": 112,
        "content": "Gmail and Yahoo send DMARC reports as zip/gz xml files that are hard to read. This workflow unpacks them, turns the data into a simple table, and emails you an easy-to-read report"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "60cd2143-f4a7-46a8-8e96-3a3cb13eaedd",
  "connections": {
    "set": {
      "main": [
        [
          {
            "node": "send",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "xml": {
      "main": [
        [
          {
            "node": "xml2json",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "cron": {
      "main": [
        [
          {
            "node": "dmarc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "dmarc": {
      "main": [
        [
          {
            "node": "unzip",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "unzip": {
      "main": [
        [
          {
            "node": "xml",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "xml2json": {
      "main": [
        [
          {
            "node": "set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}