Trying to save an .xlsx file attached to an email into a local directory

Hello Guys,

I am trying to fetch an email attachment which is a .xlsx file.
I moved the arraybuffer of the attachment content to msg.payload and used file node to try to save it as test.xlsx.
But the saved .xlsx file is currupt.
And the strage part is it did work as i intended once so i am totaly lost what exactly is the problem.
Ive mentioned the code for the flow below.

[{"id":"227f4b0e.7a7ac4","type":"inject","z":"ed20e334.d0265","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":917,"wires":[["a512ec0f.4c98a"]]},{"id":"a512ec0f.4c98a","type":"e-mail in","z":"ed20e334.d0265","name":"Office email","protocol":"IMAP","server":"outlook.office365.com","useSSL":true,"port":"993","box":"IOT","disposition":"Read","criteria":"FLAGGED","repeat":"300","fetch":"trigger","inputs":1,"x":110,"y":997,"wires":[["f4b39742.fb9b58"]]},{"id":"f0d976ef.784b68","type":"debug","z":"ed20e334.d0265","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":997,"wires":[]},{"id":"f4b39742.fb9b58","type":"filter","z":"ed20e334.d0265","name":"mfg cost","property":"topic","propertyType":"msg","asArray":false,"itemProperty":"","itemPropertyType":"item","rules":[{"t":"cont","v":"Mfg cost for the month of ","vt":"str","output":1}],"checkall":"true","outputs":1,"x":260,"y":997,"wires":[["9eb64d36.1aa6d"]]},{"id":"9eb64d36.1aa6d","type":"change","z":"ed20e334.d0265","name":"move to payload","rules":[{"t":"move","p":"attachments[0].content","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":997,"wires":[["1bbd5c41.6018d4"]]},{"id":"1bbd5c41.6018d4","type":"file","z":"ed20e334.d0265","name":"test","filename":"E:\\greenshot\\email attachment test\\test.xlsx","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"utf8","x":610,"y":997,"wires":[["f0d976ef.784b68"]]}]

regards,
Gourav


1 Like

Well you probably shouldn't add a carriage return to the end of the file as that may corrupt it
image
Also utf8 format "may" be ok - but I would probably try binary as it won't try and be too clever with extended characters.

Hi, thanks for the reply. I just chnage encoding to default and it worked.

[{"id":"227f4b0e.7a7ac4","type":"inject","z":"ed20e334.d0265","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":917,"wires":[["a512ec0f.4c98a"]]},{"id":"a512ec0f.4c98a","type":"e-mail in","z":"ed20e334.d0265","name":"Office email","protocol":"IMAP","server":"outlook.office365.com","useSSL":true,"port":"993","box":"IOT","disposition":"Read","criteria":"FLAGGED","repeat":"300","fetch":"trigger","inputs":1,"x":110,"y":997,"wires":[["f4b39742.fb9b58"]]},{"id":"f0d976ef.784b68","type":"debug","z":"ed20e334.d0265","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":997,"wires":[]},{"id":"f4b39742.fb9b58","type":"filter","z":"ed20e334.d0265","name":"mfg cost","property":"topic","propertyType":"msg","asArray":false,"itemProperty":"","itemPropertyType":"item","rules":[{"t":"cont","v":"Mfg cost for the month of ","vt":"str","output":1}],"checkall":"true","outputs":1,"x":260,"y":997,"wires":[["9eb64d36.1aa6d"]]},{"id":"9eb64d36.1aa6d","type":"change","z":"ed20e334.d0265","name":"move to payload","rules":[{"t":"move","p":"attachments[0].content","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":997,"wires":[["1bbd5c41.6018d4"]]},{"id":"1bbd5c41.6018d4","type":"file","z":"ed20e334.d0265","name":"test","filename":"E:\\greenshot\\email attachment test\\test.xlsx","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":610,"y":997,"wires":[["f0d976ef.784b68"]]}]

Hi @gv_gv, it seems that your solved problem is very similar to mine. Unfortunately I cannot use your provided flow as I get "unknown node type "filter"", when importing. It would be great if you can post an updated flow here or give me a hint how to solve. Thanks!

Hi @E-J-D welcome to the forum.

It is a contrib node (type not explained by the OP).

It sems to be checking the incoming message contains the thing(s) they are interested in.
Likely a simple switch node or function node can replace this in your case. Or simply delete it and allow all emails to be processed.

Other than that, i will be closing this 5y old topic.

If my advise above doesn't help you, please open a new topic & link back to this if needed.