{
  "name": "Sync Gmail sent email contacts with Odoo mailing lists",
  "nodes": [
    {
      "id": "9ba53878-ef58-4926-b5a7-1f7e6a11db53",
      "name": "End",
      "type": "n8n-nodes-base.noOp",
      "position": [
        384,
        1008
      ]
    },
    {
      "id": "69e88df5-3338-46c2-845b-7778a54502a8",
      "name": "Step 1: Schedule Trigger every day at 7 AM",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -768,
        912
      ]
    },
    {
      "id": "8b34fc77-07b8-4cfc-aa86-94de5d323cd1",
      "name": "Step 2: Set Variables",
      "type": "n8n-nodes-base.set",
      "position": [
        -544,
        912
      ]
    },
    {
      "id": "d57d0cc8-75ed-4cba-992d-da9d8e2bd0e1",
      "name": "Step 3: Get date time",
      "type": "n8n-nodes-base.code",
      "position": [
        -336,
        912
      ]
    },
    {
      "id": "778eef83-d3d9-48aa-bfd3-b5c6a9e8cc38",
      "name": "Step 4:Get the list of emails sent 10 days ago.",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -96,
        912
      ]
    },
    {
      "id": "129e5bc6-5a4d-47b2-9bc4-4b6af38b2a7e",
      "name": "Step 5: If resultSizeEstimate has a record ==> true",
      "type": "n8n-nodes-base.if",
      "position": [
        144,
        912
      ]
    },
    {
      "id": "a919bc3d-a946-4a1d-b033-cceee803e231",
      "name": "Step 6: Split Out emails sent",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        384,
        800
      ]
    },
    {
      "id": "5ada64a1-c4b7-4a14-8a1b-0c38f55c9e8b",
      "name": "Step 7: Loop Over email sent",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        640,
        800
      ]
    },
    {
      "id": "e28369de-1c64-4e49-a7c4-0b1ec469aa9f",
      "name": "Step 8: Get email information about thread_id",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        864,
        960
      ]
    },
    {
      "id": "ba367a78-e5ad-4a35-8ad9-574360e06bc2",
      "name": "Step 9: Handling mail sorting from headers",
      "type": "n8n-nodes-base.code",
      "position": [
        640,
        960
      ]
    },
    {
      "id": "c653a801-7bf6-4142-8c0c-a3aad0737931",
      "name": "Step 10: Merge the categorized mailing lists",
      "type": "n8n-nodes-base.code",
      "position": [
        864,
        784
      ]
    },
    {
      "id": "4283c715-1651-4a49-a563-7b9db0b755d6",
      "name": "Step 14: Search email in Mailing List Contacts",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1584,
        704
      ]
    },
    {
      "id": "ff6a0581-0c15-4615-b100-d0296f9c9ae3",
      "name": "Step 15: If number of records is not 0 = true",
      "type": "n8n-nodes-base.if",
      "position": [
        1776,
        704
      ]
    },
    {
      "id": "6eb6ef12-0a42-40aa-82e6-983f2d05fee8",
      "name": "Step 16.1\" Check if list_ids contains 020.Good-to-send",
      "type": "n8n-nodes-base.code",
      "position": [
        1984,
        608
      ]
    },
    {
      "id": "07637692-9598-4a2c-90e4-7cb47d874e66",
      "name": "Step 16.2: Add new email in Mailing List Contacts",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1984,
        800
      ]
    },
    {
      "id": "5c23917e-e814-4c11-ac3c-cbc155a7af82",
      "name": "Step 17: If list_ids = true",
      "type": "n8n-nodes-base.if",
      "position": [
        2192,
        704
      ]
    },
    {
      "id": "c0df8b49-2354-4ef0-8985-451d56b733af",
      "name": "Step 18: Update email in Mailing List Contacts",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2400,
        704
      ]
    },
    {
      "id": "50510a57-bdbb-46de-91cc-ab11833e9fec",
      "name": "Step 19: Return all data from step 10.",
      "type": "n8n-nodes-base.code",
      "position": [
        2624,
        496
      ]
    },
    {
      "id": "5c7f9750-b12a-46ca-90be-592ed3b606c1",
      "name": "Step 20: Split Out bounceEmails",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        2816,
        496
      ]
    },
    {
      "id": "2819cfa6-6a12-4890-9f5b-57f8865055ca",
      "name": "Step 21: Loop Over bounceEmails",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        3024,
        496
      ]
    },
    {
      "id": "1106af9f-ecd3-4cd8-9c69-2421b61c2258",
      "name": "Step 22: Search email in Blacklisted Email Addresses",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3024,
        688
      ]
    },
    {
      "id": "d9b26770-e5a6-49f1-bb74-1f1e399837e3",
      "name": "Step 23: If number of records is not 0 = true",
      "type": "n8n-nodes-base.if",
      "position": [
        3232,
        688
      ]
    },
    {
      "id": "f57626ff-2ced-42bc-8e16-0b845371fe1b",
      "name": "Step 24.1\" Check if reason_type contains Bounced",
      "type": "n8n-nodes-base.code",
      "position": [
        3440,
        592
      ]
    },
    {
      "id": "391adb70-caf3-4bc2-bb00-db5032c98ec5",
      "name": "Step 24.2: Add new email in Blacklisted Email Addresses",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3440,
        784
      ]
    },
    {
      "id": "154d44eb-f19d-4357-9387-8e7904148f10",
      "name": "Step 25: If list_ids = true",
      "type": "n8n-nodes-base.if",
      "position": [
        3648,
        688
      ]
    },
    {
      "id": "a33c682d-5860-47f0-aaf8-3a0c4ca3fe85",
      "name": "Step 26: Update Reason Type of email in Blacklisted Email Addresses",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3856,
        688
      ]
    },
    {
      "id": "f9675854-47ef-4550-bbe1-67f307212ebf",
      "name": "Step 27: If has record bounceEmails",
      "type": "n8n-nodes-base.if",
      "position": [
        1328,
        1280
      ]
    },
    {
      "id": "423d6ac0-5304-4db4-af1f-df7eaf952e5a",
      "name": "Step 28: Split Out bounceEmails",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1552,
        1184
      ]
    },
    {
      "id": "9290cfbb-47af-4ec4-b9c3-b80c4ad75a52",
      "name": "Step 29: Loop Over bounceEmails",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1792,
        1184
      ]
    },
    {
      "id": "e6bd0479-de0d-4330-a781-9e7ceec6f2a5",
      "name": "Step 30: Search email in Blacklisted Email Addresses",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1792,
        1376
      ]
    },
    {
      "id": "8d452689-58a7-4e27-a513-aed4efa5bd3d",
      "name": "Step 31: If number of records is not 0 = true",
      "type": "n8n-nodes-base.if",
      "position": [
        2000,
        1376
      ]
    },
    {
      "id": "a5536923-dd58-4dc8-8de2-106b3fc12add",
      "name": "Step 32.1: Check if reason_type contains Bounced",
      "type": "n8n-nodes-base.code",
      "position": [
        2224,
        1280
      ]
    },
    {
      "id": "f7e15ab6-b89c-40fd-a204-9cd262844774",
      "name": "Step 32.2: Add new email in Blacklisted Email Addresses",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2224,
        1472
      ]
    },
    {
      "id": "cd6e113f-9f2b-44d3-966a-b7158eefd37f",
      "name": "Step 33: If list_ids = true",
      "type": "n8n-nodes-base.if",
      "position": [
        2448,
        1376
      ]
    },
    {
      "id": "599b271f-a57d-487e-a5f3-2408f0045556",
      "name": "Step 34: Update Reason Type of email in Blacklisted Email Addresses",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2672,
        1376
      ]
    },
    {
      "id": "88e9774e-2ad8-420e-b9e8-ddea50d6b1f8",
      "name": "End1",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1552,
        1408
      ]
    },
    {
      "id": "f5c38d97-58ea-415b-b0cc-8017e90a2fae",
      "name": "End2",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2000,
        1184
      ]
    },
    {
      "id": "02dfebf5-61a0-4e98-b294-a6c894d69350",
      "name": "End3",
      "type": "n8n-nodes-base.noOp",
      "position": [
        3232,
        496
      ]
    },
    {
      "id": "b3f1daea-35fe-46ce-8f3d-ebd85c94596f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        592
      ],
      "parameters": {
        "width": 688,
        "height": 592,
        "content": "## 2. Loop Over the list of emails sent 10 days ago.\n- We can customize the number of days in \"Step 2: Set Variables\" using the days_ago field.\n- Each iteration checks if anyone has responded to the s"
      }
    },
    {
      "id": "eb3c1e20-dbf9-4eec-9531-e688137724d9",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1616,
        144
      ],
      "parameters": {
        "width": 720,
        "height": 1744,
        "content": "# Email Contacts Sync from Sent Mailbox to Odoo\nThis workflow automatically extracts recipient email addresses from previously sent emails, validates and cleans the data, and synchronizes only deliver"
      }
    },
    {
      "id": "679b5a96-57fa-49b6-96d4-d37111a86b14",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -848,
        672
      ],
      "parameters": {
        "width": 1392,
        "height": 512,
        "content": "## 1. Set Variables and Get datetime\n- Set Variables and Get datetime\n- Get the list of emails sent 10 days ago.\n- In Step 6, Split Out is used to split the \"messages\" array into multiple individual i"
      }
    },
    {
      "id": "5a17590c-ead7-4b8c-95af-cf820e2b0b1d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        352
      ],
      "parameters": {
        "width": 1312,
        "height": 640,
        "content": "## 3. Push the list of deliverable emails to the internal Odoo system.\n- For each email in the deliverable emails list, we check if it exists in the internal Odoo system.\n- If not, create a new contac"
      }
    },
    {
      "id": "a187d542-9aa6-402e-a53c-cdd444cd9ff3",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2592,
        352
      ],
      "parameters": {
        "width": 1440,
        "height": 640,
        "content": "## 4. Add emails from the bounce email list to the \"Blacklisted Email Addresses\" in the internal Odoo system.\n- For each email in the bounce email list, we check if it exists in the internal Odoo syst"
      }
    },
    {
      "id": "9ccf3eee-9ab8-4987-875d-780694dc675c",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1264,
        1008
      ],
      "parameters": {
        "width": 1584,
        "height": 656,
        "content": "## 5. Same.....Add emails from the bounce email list to the \"Blacklisted Email Addresses\" in the internal Odoo system.\n- For each email in the bounce email list, we check if it exists in the internal "
      }
    },
    {
      "id": "2a5e0291-4bdb-4d42-b2be-bb90c21e5783",
      "name": "Step 11: If has record deliverableEmails",
      "type": "n8n-nodes-base.if",
      "position": [
        1072,
        784
      ]
    },
    {
      "id": "aba0d981-46b9-4aa6-ac40-ff7580964570",
      "name": "Step 12: Split Out deliverableEmails list",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1328,
        640
      ]
    },
    {
      "id": "e75870af-bc4a-4dce-b1f4-e9d41d71c549",
      "name": "Step 13: Loop Over deliverableEmails",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1584,
        512
      ]
    }
  ],
  "connections": {
    "Step 2: Set Variables": {
      "main": [
        [
          {
            "node": "Step 3: Get date time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 3: Get date time": {
      "main": [
        [
          {
            "node": "Step 4:Get the list of emails sent 10 days ago.",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 17: If list_ids = true": {
      "main": [
        [
          {
            "node": "Step 13: Loop Over deliverableEmails",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 18: Update email in Mailing List Contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 25: If list_ids = true": {
      "main": [
        [
          {
            "node": "Step 21: Loop Over bounceEmails",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 26: Update Reason Type of email in Blacklisted Email Addresses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 33: If list_ids = true": {
      "main": [
        [
          {
            "node": "Step 29: Loop Over bounceEmails",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 34: Update Reason Type of email in Blacklisted Email Addresses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 7: Loop Over email sent": {
      "main": [
        [
          {
            "node": "Step 10: Merge the categorized mailing lists",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 8: Get email information about thread_id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 6: Split Out emails sent": {
      "main": [
        [
          {
            "node": "Step 7: Loop Over email sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 20: Split Out bounceEmails": {
      "main": [
        [
          {
            "node": "Step 21: Loop Over bounceEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 21: Loop Over bounceEmails": {
      "main": [
        [
          {
            "node": "End3",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 22: Search email in Blacklisted Email Addresses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 28: Split Out bounceEmails": {
      "main": [
        [
          {
            "node": "Step 29: Loop Over bounceEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 29: Loop Over bounceEmails": {
      "main": [
        [
          {
            "node": "End2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 30: Search email in Blacklisted Email Addresses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 27: If has record bounceEmails": {
      "main": [
        [
          {
            "node": "Step 28: Split Out bounceEmails",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "End1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 13: Loop Over deliverableEmails": {
      "main": [
        [
          {
            "node": "Step 19: Return all data from step 10.",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 14: Search email in Mailing List Contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 19: Return all data from step 10.": {
      "main": [
        [
          {
            "node": "Step 20: Split Out bounceEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 11: If has record deliverableEmails": {
      "main": [
        [
          {
            "node": "Step 12: Split Out deliverableEmails list",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 27: If has record bounceEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 12: Split Out deliverableEmails list": {
      "main": [
        [
          {
            "node": "Step 13: Loop Over deliverableEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 1: Schedule Trigger every day at 7 AM": {
      "main": [
        [
          {
            "node": "Step 2: Set Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 9: Handling mail sorting from headers": {
      "main": [
        [
          {
            "node": "Step 7: Loop Over email sent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 10: Merge the categorized mailing lists": {
      "main": [
        [
          {
            "node": "Step 11: If has record deliverableEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 15: If number of records is not 0 = true": {
      "main": [
        [
          {
            "node": "Step 16.1\" Check if list_ids contains 020.Good-to-send",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 16.2: Add new email in Mailing List Contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 23: If number of records is not 0 = true": {
      "main": [
        [
          {
            "node": "Step 24.1\" Check if reason_type contains Bounced",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 24.2: Add new email in Blacklisted Email Addresses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 31: If number of records is not 0 = true": {
      "main": [
        [
          {
            "node": "Step 32.1: Check if reason_type contains Bounced",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Step 32.2: Add new email in Blacklisted Email Addresses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 8: Get email information about thread_id": {
      "main": [
        [
          {
            "node": "Step 9: Handling mail sorting from headers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 14: Search email in Mailing List Contacts": {
      "main": [
        [
          {
            "node": "Step 15: If number of records is not 0 = true",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 18: Update email in Mailing List Contacts": {
      "main": [
        [
          {
            "node": "Step 13: Loop Over deliverableEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 4:Get the list of emails sent 10 days ago.": {
      "main": [
        [
          {
            "node": "Step 5: If resultSizeEstimate has a record ==> true",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 24.1\" Check if reason_type contains Bounced": {
      "main": [
        [
          {
            "node": "Step 25: If list_ids = true",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 32.1: Check if reason_type contains Bounced": {
      "main": [
        [
          {
            "node": "Step 33: If list_ids = true",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 16.2: Add new email in Mailing List Contacts": {
      "main": [
        [
          {
            "node": "Step 13: Loop Over deliverableEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 5: If resultSizeEstimate has a record ==> true": {
      "main": [
        [
          {
            "node": "Step 6: Split Out emails sent",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "End",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 22: Search email in Blacklisted Email Addresses": {
      "main": [
        [
          {
            "node": "Step 23: If number of records is not 0 = true",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 30: Search email in Blacklisted Email Addresses": {
      "main": [
        [
          {
            "node": "Step 31: If number of records is not 0 = true",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 16.1\" Check if list_ids contains 020.Good-to-send": {
      "main": [
        [
          {
            "node": "Step 17: If list_ids = true",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 24.2: Add new email in Blacklisted Email Addresses": {
      "main": [
        [
          {
            "node": "Step 21: Loop Over bounceEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 32.2: Add new email in Blacklisted Email Addresses": {
      "main": [
        [
          {
            "node": "Step 29: Loop Over bounceEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 26: Update Reason Type of email in Blacklisted Email Addresses": {
      "main": [
        [
          {
            "node": "Step 21: Loop Over bounceEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Step 34: Update Reason Type of email in Blacklisted Email Addresses": {
      "main": [
        [
          {
            "node": "Step 29: Loop Over bounceEmails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}