{
  "name": "Poll multiple Gmail accounts with unified data table storage & Discord notifications",
  "nodes": [
    {
      "id": "188b3582-4c1f-4db2-9015-6f0c74d061e8",
      "name": "Run Node With Credentials X",
      "type": "n8n-nodes-run-node-with-credentials-x.runNodeWithCredentialsX",
      "position": [
        1088,
        320
      ]
    },
    {
      "id": "4c0e6519-d20b-450c-8d10-6769eb3f7b13",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        64,
        320
      ]
    },
    {
      "id": "67ba019f-85d7-4e32-9d2d-75b325db3d47",
      "name": "Code in JavaScript",
      "type": "n8n-nodes-base.code",
      "position": [
        800,
        320
      ]
    },
    {
      "id": "f19e61bd-356a-436c-b2bc-17d1e9a1d3c3",
      "name": "upsert emails",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1968,
        304
      ]
    },
    {
      "id": "fc88372d-71a7-4a71-b772-91b526129f67",
      "name": "Update last_polled",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1760,
        304
      ]
    },
    {
      "id": "0031fcaa-5aea-4476-8572-dded88512cc3",
      "name": "Update last_polled1",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        1760,
        464
      ]
    },
    {
      "id": "3b84eb3a-62f1-4310-924e-2e0388a908bb",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        512,
        320
      ]
    },
    {
      "id": "0bbedf6e-af59-4995-95c1-7eaef3712f2e",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        1232,
        -64
      ]
    },
    {
      "id": "df4bff3c-cdaa-473c-b4c5-dd3bdac234c4",
      "name": "Send a message",
      "type": "n8n-nodes-base.discord",
      "position": [
        1664,
        -64
      ]
    },
    {
      "id": "fb78da17-8af9-41b2-8ead-e7c7df840d1c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -496
      ],
      "parameters": {
        "width": 592,
        "height": 640,
        "content": "### How It Works (node-by-node):\n\n1. Schedule Trigger fires every hour (or your preferred interval).\n\n2. Fetch all email account rows from the cold_email_accounts table.\n\n3. Split In Batches loops thr"
      }
    },
    {
      "id": "97c9e764-66c0-4936-8df8-f74ccdc99c26",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "position": [
        1440,
        -64
      ]
    },
    {
      "id": "e7bf6c35-2b03-4742-b3d0-57f8c4265910",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        208
      ],
      "parameters": {
        "width": 656,
        "height": 256,
        "content": "## Get Email Accounts\nLoads all email accounts to be polled."
      }
    },
    {
      "id": "55a2d33c-6457-4db2-8dbd-a84902faa9ca",
      "name": "Get All Email Accounts",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        288,
        320
      ]
    },
    {
      "id": "53c05718-b21b-4f67-9b7e-9e371bfdf4bd",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        208
      ],
      "parameters": {
        "width": 288,
        "height": 256,
        "content": "## Polling Time Calculator\nCalculates the polling time range in Epoch."
      }
    },
    {
      "id": "51e7a928-d244-458e-955a-291c9a25f05c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1024,
        208
      ],
      "parameters": {
        "width": 640,
        "height": 256,
        "content": "## Get Gmail Messages Dynamically\nRuns Gmail nodes dynamically using OAuth credentials from the data table."
      }
    },
    {
      "id": "da3085bb-3404-4e33-a266-e6f524399d50",
      "name": "Email Normalization",
      "type": "n8n-nodes-base.code",
      "position": [
        1504,
        304
      ]
    },
    {
      "id": "f7e73855-d33a-4662-ba56-f8862aa747a1",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1696,
        144
      ],
      "parameters": {
        "width": 448,
        "height": 544,
        "content": "## Add to Data Tables\nUpserts new emails into the All Emails table and avoids duplicates.\nUpdates last_polled for the current email account after processing."
      }
    },
    {
      "id": "b2b0cebb-89f3-4695-b85e-5d3d8f4ad80f",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        752,
        -160
      ],
      "parameters": {
        "width": 1104,
        "height": 256,
        "content": "## Send Notification on Discord Channel\nSends a summary message with the number of newly received emails."
      }
    },
    {
      "id": "9e1681dd-0181-4e9a-86e7-e268a80116c7",
      "name": "Get new emails if any",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        784,
        -48
      ]
    },
    {
      "id": "d4ed6f2f-555b-44a8-abaf-ef547848f944",
      "name": "If new email found",
      "type": "n8n-nodes-base.if",
      "position": [
        1280,
        320
      ]
    },
    {
      "id": "f8e45d30-c99d-4712-8233-627d8e9ca565",
      "name": "If new email found1",
      "type": "n8n-nodes-base.if",
      "position": [
        1008,
        -48
      ]
    }
  ],
  "connections": {
    "Limit": {
      "main": [
        [
          {
            "node": "Send a message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "upsert emails": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Get new emails if any",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get All Email Accounts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "Run Node With Credentials X",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If new email found": {
      "main": [
        [
          {
            "node": "Email Normalization",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update last_polled1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update last_polled": {
      "main": [
        [
          {
            "node": "upsert emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Email Normalization": {
      "main": [
        [
          {
            "node": "Update last_polled",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If new email found1": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update last_polled1": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get new emails if any": {
      "main": [
        [
          {
            "node": "If new email found1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get All Email Accounts": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Node With Credentials X": {
      "main": [
        [
          {
            "node": "If new email found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}