Imap Node trigger twice for the same email

Imap Node trigger twice for the same email

Not the error, but execute same execution get trigger twice as same.

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and{
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "867e7023-cc90-4df5-a49a-6a0eb3744ec9",
              "name": "From",
              "value": "={{ $json.from.match(/<([^>]+)>/)?.[1] || $json.from }}",
              "type": "string"
            },
            {
              "id": "0738d15f-dafb-4aff-9032-8a6456955970",
              "name": "To",
              "value": "={{ $json.to }}",
              "type": "string"
            },
            {
              "id": "131b4ec5-a735-48cd-80e2-25813dbd3e42",
              "name": "text",
              "value": "={{ $json.textHtml }}",
              "type": "string"
            },
            {
              "id": "70706f2e-fade-4500-b396-e24b8bd6e092",
              "name": "Report Date",
              "value": "={{ $today.toString().split('T')[0] }}",
              "type": "string"
            },
            {
              "id": "95da3110-6ddb-4bf4-b0fc-14f3ebd1e75a",
              "name": "threadId",
              "value": "={{ $json.metadata['message-id'] }}",
              "type": "string"
            },
            {
              "id": "861ac2d1-e6bd-4cc4-b914-90bf92125bfe",
              "name": "HubSpotAccessToken",
              "value": "6",
              "type": "string"
            },
            {
              "id": "8a81ff47-c724-450a-884f-6e517cf5812e",
              "name": "Salesforce",
              "value": "SF6",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "21c5e5b5-2bc1-47d7-9814-24520134d06e",
      "name": "Combine Email Details",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        16,
        -80
      ],
      "alwaysOutputData": false,
      "retryOnFail": true,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "workflowId": {
          "__rl": true,
          "value": "8Nqo0m4WMug9Yqrt",
          "mode": "id"
        },
        "workflowInputs": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        },
        "options": {}
      },
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1.2,
      "position": [
        288,
        -192
      ],
      "id": "be28ec8f-7c09-4845-b043-baa35a070e79",
      "name": "Execute Workflow",
      "retryOnFail": true,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -192,
        -96
      ],
      "id": "6790ae8d-93f4-43d6-994f-115fc6049466",
      "name": "Loop Over Items"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "name": "Replace Me",
      "typeVersion": 1,
      "position": [
        80,
        -288
      ],
      "id": "9c13b070-c619-4064-a8f7-0cec6b011d03"
    },
    {
      "parameters": {
        "amount": 3
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        288,
        16
      ],
      "id": "609efedc-003e-40e8-ba86-e80de53814bf",
      "name": "Wait",
      "webhookId": "d0174275-8179-487e-af2e-2374ee82a2f1"
    },
    {
      "parameters": {
        "options": {
          "customEmailConfig": "[\"UNSEEN\"]",
          "forceReconnect": 10
        }
      },
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 2,
      "position": [
        -432,
        -96
      ],
      "id": "f0c11a04-bdf9-4bc4-8fc9-1dcb6b78b6a5",
      "name": "[email protected]",
      "credentials": {
        "imap": {
          "id": "ZVBQQQO6oGgfTPgQ",
          "name": "SF6 [email protected]"
        }
      }
    }
  ],
  "connections": {
    "Combine Email Details": {
      "main": [
        [
          {
            "node": "Execute Workflow",
            "type": "main",
            "index": 0
          },
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Replace Me",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Combine Email Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "[email protected]": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "704c4009e71f884947e279db464c4192e7a1913d2b4500ee29d23096fe050e92"
  }
} paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: You’re on 1.104.1
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): self host
  • Operating system:

Hi @Ahmad_Azhar, thanks for sharing the workflow.

What you’re seeing happens before any “error” exists. The IMAP Trigger works on an at-least-once delivery model, not exactly-once. This means the trigger can emit the same email more than once if the message is still considered UNSEEN when the connection polls again.

In your case, a few things line up with that behavior:

  • The trigger is filtering on UNSEEN
  • forceReconnect is enabled
  • There’s a Wait node that delays completion
  • The email is only marked as seen after the workflow finishes

So if the IMAP connection reconnects or polls again before the message state is updated on the mail server, the same email is picked up twice. That’s why you see duplicate executions even though nothing “fails”.

Because of this, the IMAP Trigger doesn’t guarantee single execution per email.

trade-offs

  1. Deduplicate in the workflow
  2. Reduce reconnects / remove the Wait loop
  3. Accept duplicates and make downstream steps idempotent

Let me know how it goes.

My workflow takes like 10-12 seconds to complete its execution how can I resolve it to be not duplicate it

@Ahmad_Azhar

The 10–12 seconds themselves are not the issue. The key point is that the email is only marked as SEEN after the workflow finishes. While the workflow is still running, the message remains UNSEEN, so the IMAP trigger can pick up the same email again on the next check.

This is expected behavior with IMAP (it works in an at-least-once mode).

To avoid duplicates, the safest approach is to deduplicate in the workflow, for example by checking metadata.message-id and skipping it if it was already processed. Making the trigger workflow finish faster can reduce duplicates, but it won’t fully prevent them.

Let me know if it works.

I tried it, but the execution time for both execution in just some milliseconds. It still doesn’t work.

Hi @Ahmad_Azhar, welcome!

I can see you’re using an old Email Trigger (IMAP) node:
image

The latest version includes an option that might solve your issue:

1 Like