Downloading Email Attachments using Inner and Outer Loop

Hi-

I’m trying to upload email attachments to a document repository using the IMAP node. I have seen in some other posts that there are issues with the IMAP node. I too am facing these. One issue is that the node doesn’t fire on new emails, and when it does it triggers on multiple new emails. I have used the SplitintoBatch node to solve for this.

However each email can have multiple attachments and so im trying to splitintoBatch again. In short I need an inner and outer loop, the outer loop to process the emails, the inner loop to process/upload the attachments.

I cant get it to work. In the example below I have two emails, the first with 2 attachments, the other with 3 attachments. It works as intended but never “reenters” the innerloop–the expected result is 5 executions in the inner loop (1 per document) and 2 in the outer loop (1 per email). Is the scenario presented achievable in N8N? Can SplitintoBatch be used twice in one workflow?

Welcome to the community @srcalcutta!

In this case it would probably be the easiest if you split it into two workflows.

  • one workflow with the inner loop which processes an email loops over the attachments
  • one workflow with the outer loop which iterates over the emails

You can call the inner “Email process workflow” in the outer “Receive & Iterate workflow” via an Execute Workflow Node.