Gmail For Each: Process the same email multiple times

Description

I am trying to automate Gmail processing with the flow below.
I seem to be processing the same email multiple times at unspecified intervals.
Is there a cause for this?
If anyone could help, I would appreciate it.

Start Process

├─ While: Are there any unread emails that still need to be processed?

│ └─ For Each: Iterate through each email
│ │
│ ├─ Try Catch
│ │ │
│ │ ├─ Try
│ │ │ ├─ Check whether the email has attachments
│ │ │ ├─ Download attachments / Read email body
│ │ │ ├─ Parse content using Regular Expressions
│ │ │ ├─ Save the processing result
│ │ │ └─ Mark the email as Read
│ │ │
│ │ └─ Catch
│ │ └─ Log the error
│ │
│ └─ Continue to the next email

└─ End Process

Link

Date

2026-06-25

Related UiPath products

Studio

Hi @x.ji,

The issue is While loop. If the unread email list isn’t refreshed on each iteration, the loop may continue processing the same email collection even after an email has been marked as Read.

If you’re already retrieving all unread emails and processing them with a For Each loop, you likely don’t need the While loop. The For Each process each email once.

Thanks

One possible pattern is that the read mark was set at the end of the forEach loop, but before that is reflected, it goes back to the while loop and retrieves emails again, causing previously processed emails to be processed again.
There might be such a situation…

As a backward-looking countermeasure, maybe we could try waiting a few seconds after exiting the foreach…

If the duplicates are not emails around those cut-off points, then I’m sorry for that.