Files

File email attachments into Nextcloud with n8n

An IMAP trigger watches a mailbox, a Code node splits each message into one item per attachment, and every file is uploaded to a dated path in Nextcloud.

Trigger
Email Trigger (IMAP), on new mail
Nodes
5
Requires
IMAP, Nextcloud
Category
Files
From the course
Vaultwarden and Nextcloud
Published
2026-09-10

Node types used

  • Email Trigger (IMAP)
  • If
  • Code
  • Nextcloud
  • No Operation
Workflow diagram: File email attachments into Nextcloud with n8ntruefalseEmail Trigger (IMAP)Has an attachment?One item per attachme…One item per attachmentUpload to NextcloudNo attachment
TriggerActionLogicOutput

What it does

Invoices, signed forms and photos arrive as email attachments and end up living in one person mailbox, where nobody else can find them and no backup covers them. Moving them by hand works until the week it does not.

An Email Trigger (IMAP) node watches the mailbox in resolved format, forcing a reconnect every 60 minutes so a dropped IMAP connection does not silently stop the workflow. An If node counts the keys on $binary and only continues when there is at least one attachment. Because n8n gives one item per message with the attachments as several binary properties on it, a Code node loops over every binary key and emits one new item per attachment, copying the original JSON and adding sourceBinaryProperty so you can still tell which attachment came from where, and normalising the binary property name to attachment. A Nextcloud node then uploads each item to /Team Files/Incoming/ with the filename prefixed by the current date in yyyy-LL-dd form. Messages with no attachment go to a NoOp node so the branch is explicit rather than a dead end.

Nothing is filed by sender, subject or type: every attachment lands in the same folder with the same date prefix. Nothing is deleted, moved or marked read in the mailbox, and no reply is sent.

Node by node

  1. 1

    Email Trigger (IMAP) Watches the mailbox and fires on new mail. Format is resolved, so attachments arrive as binary properties. allowUnauthorizedCerts is off and forceReconnect is 60 minutes.

  2. 2

    Has an attachment? An If node testing Object.keys($binary ?? {}).length greater than 0, so a plain text email does not reach the upload.

  3. 3

    One item per attachment A Code node that iterates every binary key on every incoming item and pushes a new item for each, keeping the original json, adding sourceBinaryProperty with the original key name, and putting the file on a binary property called attachment. This is what makes a three-attachment email into three uploads.

  4. 4

    Upload to Nextcloud Uploads the attachment binary property to /Team Files/Incoming/ with the path built as the current date in yyyy-LL-dd followed by a hyphen and the original filename.

  5. 5

    No attachment The false branch. A NoOp node so a message with nothing attached ends cleanly and visibly.

Setup after import

  1. 1

    Create an IMAP credential for the mailbox you want watched and select it on Email Trigger (IMAP). The export ships without one attached.

  2. 2

    Create a Nextcloud credential and select it on Upload to Nextcloud.

  3. 3

    Create the folder /Team Files/Incoming in Nextcloud, or change the path on the upload node to a folder that exists.

  4. 4

    Use a dedicated mailbox or an alias rather than a personal inbox. The trigger acts on everything that arrives.

  5. 5

    Send yourself a test message with two attachments and confirm two files appear, not one.

Limits

  • Everything lands in one folder. No routing by sender, subject or file type.

  • Two files with the same name arriving on the same day collide on the same path.

  • The mailbox is left untouched: nothing is marked read, moved or deleted after filing.

  • No file size or type checks, so whatever the mailbox accepts is uploaded.

Download the workflow

The 5 node export as n8n reads it. Credential ids, personal values and real endpoints are replaced with placeholders, so nothing here can reach an account that is not yours. No email, no account.

Download email-attachments-to-nextcloud.json

Get help with this in the community

If the import fails, if a node errors on the first run, or if you want to point this at a service it does not cover yet, post it in the free House of Loops community. Say which template it is and paste the error. Shannon Atkinson answers, and the answer stays there for the next person who hits the same thing.

Ask in the community