Attachments in node-red

Hello everybody,
I create a flow that is using node-red-node-email to get certain unread emails from INBOX.
Can someone help me on how to read the attachments (excel) from the email and send the payload to a robot workflow?
Attachments are in base64 (content), as you can see here:

[{"type":"attachment","content":[208,207,17,224,161,177,26,225,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,62,0,3,0,254,255,9,0,6,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,54,0,0,0,0,0,0,0,0,16,0,0,254,255,255,255,0,0,0,0,254,255,255,255,0,0,0,0,53,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,9,8,16,0,0,6,5,0,84,56,205,7,193,0,2,0,6,8,0,0,225,0,2,0,176,4,193,0,2,0,0,0,226,0,0,0,92,0,112,0,19,0,0,65,110,97,32,67,114,105,115,116,105,110,97,32,77,111,114,101,110,111,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,66,0,2,0,176,4,97,1,2,0,0,0,192,1,0,0,61,1,2,0,1,0,156,0,2,0,17,0,25,0,2,0,0,0,18,0,2,0,0,0,19,0,2,0,0,0,175,1,2,0,0,0,188,1,2,0,0,0,61,0,18,0,0,0,0,0,66,84,149,31,56,0,0,0,0,0,1,0,88,2,64,0,2,0,0,0,141,0,2,0,0,0,34,0,2,0,0,0,14,0,2,0,1,0,183,1,2,0,0,0,218,0,2,0,0,0,49,0,30,0,220,0,0,0,8,0,144,1,0,0,0,2,0,0,7,1,67,0,97,0,108,0,105,0,98,0,114,0,105,0,49,0,30,0,220,0,0,0,8,0,144,1,0,0,0,2,0,0,7,1,67,0,97,0,108,0,105,0,98,0,114,0,105,0,49,0,30,0,220,0,0,0,8,0,144,1,0,0,0,2,0,0,7,1,67,0,97,0,108,0,105,0,98,0,114,0,105,0,49,0,30,0,220,0,0,0,8,0,144,1,0,0,0,2,0,0,7,1,67,0,97,0,108,0,105,0,98,0,114,0,105,0,49,0,30,0,220,0,0,0,8,0,144,1,0,0,0,2,0,0,7,1,67,0,97,0,108,0,105,0,98,0,114,0,105,0,49,0,42,0,104,1,0,0,54,0,144,1,0,0,0,2,0,0,13,1,67,0,97,0,108,0,105,0,98,0,114,0,105,0,32,0,76,0,105,0,103,0,104,0,116,0,49,0,30,0],"contentType":"application/vnd.ms-excel","partId":"2","release":null,"contentDisposition":"attachment","filename":"6 Pós-Pago Teste EFATURA ICCID 4008404_4008409.xls","headers":{"content-type":{"value":"application/vnd.ms-excel","params":{"name":"6 Pós-Pago Teste EFATURA ICCID 4008404_4008409.xls"}},"content-description":"=?iso-8859-1?Q?6_P=F3s-Pago_Teste_EFATURA_ICCID_4008404=5F4008409.xls?=","content-disposition":{"value":"attachment","params":{"filename":"6 Pós-Pago Teste EFATURA ICCID 4008404_4008409.xls","size":"28672","creation-date":"Tue, 13 Dec 2022 13:04:10 GMT","modification-date":"Tue, 13 Dec 2022 13:00:33 GMT"}},"content-transfer-encoding":"base64"},"checksum":"0e9e7cece72f119073619538424316a8","size":28672}]

My email flow

Thanks

I have not tested this in a long time, and I don’t have time to do it right now, but see if this helps you in the right direction

[
    {
        "id": "8d4e7cd9.9ebca",
        "type": "comment",
        "z": "584092c4.71933c",
        "name": "Send email with File Attachment",
        "info": "",
        "x": 210,
        "y": 320,
        "wires": []
    },
    {
        "id": "e7ad8ab5.4947a8",
        "type": "array-loop",
        "z": "584092c4.71933c",
        "name": "Loop each attachment",
        "key": "key",
        "keyType": "msg",
        "reset": true,
        "resetValue": "value-null",
        "array": "attachments",
        "arrayType": "msg",
        "x": 500,
        "y": 380,
        "wires": [
            [
                "19e174b1.614c2b"
            ],
            [
                "cfbb8400.b85f78"
            ]
        ]
    },
    {
        "id": "dc937ad2.c27888",
        "type": "debug",
        "z": "584092c4.71933c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 910,
        "y": 400,
        "wires": []
    },
    {
        "id": "972dfe3d.5742a",
        "type": "api upload file",
        "z": "584092c4.71933c",
        "filename": "filename",
        "filenametype": "msg",
        "content": "payload",
        "contenttype": "msg",
        "mimeType": "",
        "mimeTypetype": "str",
        "entity": "entity",
        "entitytype": "msg",
        "name": "",
        "x": 440,
        "y": 440,
        "wires": [
            [
                "e7ad8ab5.4947a8"
            ]
        ]
    },
    {
        "id": "cfbb8400.b85f78",
        "type": "function",
        "z": "584092c4.71933c",
        "name": "prepare for upload of file",
        "func": "msg.filename = msg.payload.filename;\nmsg.payload = msg.payload.content;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 230,
        "y": 440,
        "wires": [
            [
                "972dfe3d.5742a"
            ]
        ]
    },
    {
        "id": "3fcd9b3b.d38d74",
        "type": "function",
        "z": "584092c4.71933c",
        "name": "save email body",
        "func": "msg.body = msg.payload;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 300,
        "y": 380,
        "wires": [
            [
                "e7ad8ab5.4947a8"
            ]
        ]
    },
    {
        "id": "19e174b1.614c2b",
        "type": "function",
        "z": "584092c4.71933c",
        "name": "Prepare for robot",
        "func": "msg.payload = {};\nmsg.payload.subject = msg.topic;\nmsg.payload.body = msg.body;\nmsg.payload.from = msg.from;\nmsg.payload.attachments = [];\nmsg.attachments.forEach(x=> {\n    msg.payload.attachments.push(x.filename);\n});\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 360,
        "wires": [
            [
                "ae9fa989.0ccbe8"
            ]
        ]
    },
    {
        "id": "2d17c9f0.f80656",
        "type": "comment",
        "z": "584092c4.71933c",
        "name": "requires node-red-contrib-loop-processing",
        "info": "",
        "x": 520,
        "y": 320,
        "wires": []
    },
    {
        "id": "ae9fa989.0ccbe8",
        "type": "rpa workflow",
        "z": "584092c4.71933c",
        "queue": "5ce94386320b9ce0bc2c3d07",
        "workflow": "5f0056090e65fa3607ee5c6b",
        "name": "",
        "x": 730,
        "y": 420,
        "wires": [
            [
                "dc937ad2.c27888"
            ],
            [],
            [
                "bc27db6.4a81728"
            ]
        ]
    },
    {
        "id": "bc27db6.4a81728",
        "type": "debug",
        "z": "584092c4.71933c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "error",
        "targetType": "msg",
        "x": 900,
        "y": 440,
        "wires": []
    },
    {
        "id": "55692341.6be72c",
        "type": "e-mail in",
        "z": "584092c4.71933c",
        "d": true,
        "name": "",
        "protocol": "IMAP",
        "server": "imap.gmail.com",
        "useSSL": true,
        "autotls": "never",
        "port": "993",
        "box": "INBOX",
        "disposition": "None",
        "criteria": "UNSEEN",
        "repeat": "20",
        "fetch": "auto",
        "inputs": 0,
        "x": 150,
        "y": 380,
        "wires": [
            [
                "3fcd9b3b.d38d74"
            ]
        ]
    }
]

Hi @Allan_Zimmermann.

Thank you for the suggestion. I have already tested the flow and it’s working well!
I was able to debug the entire process and saw that the attachments are being uploaded to OpenFlow (that’s genius :slight_smile:).
I do have a couple of questions though:

  1. How do I access the data within the robot in OpenRPA?
  2. Does the ‘api upload file’ node supposed to create a collection in MongoDB? If yes, I can’t see it.
  1. you can get the files by id or filename from openrpa using download activity under mongodb
  2. no, files should NEVER be stores in a collection, a document in mongodb should never be more than 2 megabyte, so we store files in GridFS ( you can query that using fs.files or just click files in the menu in openflow )

Thank you for the information!
I asked the secound question beacuse I saw the what was filled in the upload node.
image

So my last question… how do I access the id or filename from openrpa? or How I read the all the data sent to the robot?

Thanks!

use arguments on the workflow in openrpa, and make the argument name match what yo have in msg.payload when calling the robot from nodered ( it’s case sensetive, so use lowercase for everything to make your life easier )

@Allan_Zimmermann Thanks for your support and info. I was able to finish the process, this will serve a POC in the company I work.
And hopefully (when accepted) implement OpenRPA as our tool for RPA.

1 Like

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