{
  "name": "MailGuard — Monthly Branded Client PDF Reports",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 1 * *"
            }
          ]
        }
      },
      "id": "1",
      "name": "Schedule — first of month at 09:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [240, 300],
      "notes": "Adjust the day-of-month and hour to match your business cadence (e.g. first business day, end-of-month, etc.)."
    },
    {
      "parameters": {
        "method": "GET",
        "url": "https://api.themailguard.ai/v1/domains",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            { "name": "limit", "value": "100" }
          ]
        },
        "options": {}
      },
      "id": "2",
      "name": "MailGuard — list all domains",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [460, 300],
      "credentials": {
        "httpHeaderAuth": {
          "id": "MAILGUARD_API_KEY_ID",
          "name": "MailGuard API key"
        }
      }
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "id": "3",
      "name": "Split — fan out per domain",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [680, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.themailguard.ai/v1/share-portal-pdf",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            { "name": "Accept", "value": "application/pdf" }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"mode\": \"authenticated\",\n  \"domain_id\": \"{{ $json.id }}\"\n}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "4",
      "name": "MailGuard — render branded PDF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 300],
      "credentials": {
        "httpHeaderAuth": {
          "id": "MAILGUARD_API_KEY_ID",
          "name": "MailGuard API key"
        }
      },
      "notes": "Requires Agency tier. The PDF carries your agency logo, color, and name from organizations.branding."
    },
    {
      "parameters": {
        "fromEmail": "reports@yourdomain.com",
        "toEmail": "={{ $json.client_contact_email || 'admin@' + $json.name }}",
        "subject": "=Monthly email-security report — {{ $json.name }}",
        "html": "Hi,\n\nAttached is your monthly email-security report for {{ $json.name }}.\n\nIt covers DMARC, SPF, DKIM, MTA-STS, and TLS-RPT for the past month, with our recommendations.\n\nQuestions? Reply to this email — we are here to help.",
        "attachments": "data",
        "options": {}
      },
      "id": "5",
      "name": "Email — send PDF to client",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [1120, 300],
      "credentials": {
        "smtp": {
          "id": "SMTP_CRED_ID",
          "name": "Outbound SMTP"
        }
      }
    }
  ],
  "connections": {
    "Schedule — first of month at 09:00": {
      "main": [[{ "node": "MailGuard — list all domains", "type": "main", "index": 0 }]]
    },
    "MailGuard — list all domains": {
      "main": [[{ "node": "Split — fan out per domain", "type": "main", "index": 0 }]]
    },
    "Split — fan out per domain": {
      "main": [[{ "node": "MailGuard — render branded PDF", "type": "main", "index": 0 }]]
    },
    "MailGuard — render branded PDF": {
      "main": [[{ "node": "Email — send PDF to client", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveExecutionProgress": true
  },
  "tags": [{ "name": "mailguard" }, { "name": "agency" }, { "name": "client-reports" }],
  "meta": {
    "schema": "mailguard-integration-template/v1",
    "documentation_url": "https://themailguard.ai/integrations/n8n-monthly-client-report-pdf",
    "mailguard_api_version": "v1",
    "min_plan": "agency",
    "scopes_required": ["domains:read", "pdf:export"],
    "notes": "client_contact_email is expected to live on each domain row as a tag or custom field. If you don't store it on the domain itself, fan-out per client first via your CRM, then call MailGuard."
  }
}
