How to avoid infinite execution loop when using Gmail "Get Many Messages" with dynamic Received After date in n8n?

Hi everyone,

I’m running into an issue where my workflow keeps going into an infinite execution loop.

Here’s my setup:

  • Trigger: Gmail Trigger (Unread emails only)

  • Next step: Gmail → Get Many Messages

  • In the Received After field, I’m using this expression:

    {{ new Date().toISOString().slice(0,10) + 'T00:00:00' }}
    
    
  • The result is always something like 2025-09-27T00:00:00.

The problem is that every time the workflow executes, this expression recalculates to today’s midnight. As a result, Gmail keeps returning the same set of emails, which triggers the workflow again → causing an endless loop.

My question:
What’s the best practice in n8n to avoid this loop? Should I:

  • Rely only on Gmail Trigger and remove the “Get Many Messages” node?

  • Use $now or $prevNode to calculate a relative time range instead of resetting to midnight every run?

  • Or is there a way to de-duplicate emails (by ID or threadId) so they don’t keep re-triggering the workflow?

I’d appreciate any suggestions or examples of how you’ve handled this problem. Thanks!

hello @alien4817

Use a Remove Duplicates node with the “Remove Items processed in previous executions“ option after your gmail trigger node

2 Likes

thanks for your kindness, it’s work!!

If the issue was resolved, please mark my post as a solution by clicking the checkbox below the post, so others can also see the solution.

1 Like

thanks a lot as a solution

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.