Using a workflow which extracts an attached email from an email (email is forwarding the attachment which is the target)
My question is regarding nodes or process to decrype or parse the .eml file for it’s contents (not the contents of the email)
I am aware js has mailparse, but this is not available for cloud version.
Has anybody found a script (js/python) or a node method to in a repeatable way extract the contents (headers, text etc) from the attached .eml?
This is using outlook - not gmail.
Information on your n8n setup
n8n version:2.9.3
Running n8n via (Docker, npm, n8n cloud, desktop app):n8n cloud
Hi @gwamm Welcome!
Unfortunately you cannot do that on n8n Cloud, for now what i can say is that you have to find an external service which can do that kind of processing for you and there you can call that service using the HTTP node, and what i would say is that if you want that kind of customization consider self hosting n8n so that you have 100% control over your n8n instance and environment.
On cloud, a Code node with plain JS can go pretty far. The .eml format is simply structured text, you should be able to parse it manually. Here is a code snippet that might help you out:
const raw = $input.first().binary.data; // base64 decode your attachment first const text = Buffer.from(raw, 'base64').toString('utf-8'); // Split headers from body const [headerSection, ...bodyParts] = text.split('\r\n\r\n'); const headers = Object.fromEntries( headerSection.split('\r\n') .filter(l => l.includes(': ')) .map(l => l.split(': ', 2)) ); const body = bodyParts.join('\r\n\r\n'); return [{ json: { headers, body } }];
This should take care of the basic single-part .eml files. For multipart MIME files it can get trickier – you’d need to detect the boundary string from the Content-Type header and split on it.