AutomationFlowsGeneral › Save Email Attachments to Nextcloud

Save Email Attachments to Nextcloud

Save Email Attachments To Nextcloud. Uses emailReadImap, nextCloud. Manual trigger; 3 nodes.

Manual trigger★★★★☆ complexity3 nodesEmail Read ImapNext Cloud
General Trigger: Manual Nodes: 3 Complexity: ★★★★☆ Added:

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "name": "IMAP Email",
      "type": "n8n-nodes-base.emailReadImap",
      "position": [
        240,
        420
      ],
      "parameters": {
        "format": "resolved",
        "mailbox": "Invoices",
        "options": {
          "customEmailConfig": "[\"ALL\"]"
        }
      },
      "typeVersion": 1
    },
    {
      "name": "Nextcloud",
      "type": "n8n-nodes-base.nextCloud",
      "position": [
        940,
        420
      ],
      "parameters": {
        "path": "=Documents/Invoices/{{$json[\"date\"]}}_{{$json[\"from\"]}}_{{$binary.file.fileName}}",
        "binaryDataUpload": true,
        "binaryPropertyName": "file"
      },
      "typeVersion": 1
    },
    {
      "name": "Map each attachment",
      "type": "n8n-nodes-base.function",
      "position": [
        620,
        420
      ],
      "parameters": {
        "functionCode": "const _ = require('lodash')\n\nconst sanitize = str => _.chain(str)\n  .replace(/[^A-Za-z0-9&.-]/g, '-') // sanitise via whitelist of characters\n  .replace(/-(?=-)/g, '') // remove repeated dashes - https://regexr.com/6ag8h\n  .trim('-') // trim any leading/trailing dashes\n  .truncate({\n    length: 60,\n    omission: '-' // when the string ends with '-', you'll know it was truncated\n  })\n  .value()\n\nconst result = _.flatMap(items.map(item => {\n  //console.log({item})\n\n  // Maps each attachment to a separate item\n  return _.values(item.binary).map(file => {\n    console.log(\"Saving attachement:\", file.fileName, 'from:', ...item.json.from.value)\n    \n    // sanitize filename but exclude extension\n    const filename_parts = file.fileName.split('.')\n    const ext = _.slice(filename_parts, filename_parts.length-1)\n    const filename_main = _.join(_.dropRight(filename_parts), '.')\n    file.fileName = sanitize(filename_main) + '.' + ext\n    \n    return {\n      json: {\n        from: sanitize(item.json.from.value[0].name),\n        date: sanitize(new Date(item.json.date).toISOString().split(\"T\")[0]) // get date part \"2020-01-01\"\n      }, \n      binary: { file }\n    }\n  })\n}))\n\n//console.log(result)\nreturn result"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "IMAP Email": {
      "main": [
        [
          {
            "node": "Map each attachment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map each attachment": {
      "main": [
        [
          {
            "node": "Nextcloud",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Save Email Attachments To Nextcloud. Uses emailReadImap, nextCloud. Manual trigger; 3 nodes.

Source: https://github.com/Zie619/n8n-workflows — original creator credit. Request a take-down →

More General workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

General

This workflow automates the daily backup of all your n8n workflows to a designated folder in Nextcloud. It ensures that you always have the last 7 days of backups available while automatically deletin

n8n, Next Cloud
General

Collects Images From Web Search Results And Send To Google Sheets. Uses awsRekognition, httpRequest, googleSheets. Manual trigger; 6 nodes.

AWS Rekognition, HTTP Request, Google Sheets
General

AI Email Auto-Responder (Ollama). Uses emailReadImap, httpRequest. Scheduled trigger; 6 nodes.

Email Read Imap, HTTP Request
General

Convert Filemaker Data Api To Flat File Array. Uses itemLists, functionItem. Manual trigger; 3 nodes.

Item Lists, Function Item
General

Write Json To Disk Binary. Uses writeBinaryFile. Manual trigger; 3 nodes.

Write Binary File