Hi All,
I am new to n8n and a beginner with no coding knowledge.
I am trying to build an AI agent (Chat Bot) as a Cyber Security Analyst to investigate malicious emails.
I am still in the initial stage, as you can see in the screenshot below, my workflow is giving two options to the user: copy & paste the raw email headers in the chat window or upload an .eml file for analysis. My if node is working fine to detect the raw email headers and attachment of the .eml file. But, I am struck at the Code node because I don’t parse email headers from .eml file, I tried multiple methods, but failed. Can somebody guide me further on how to achieve this?
I tried this open-source community node called https://nodemailer.com/extras/mailparser/ , and I am getting an error.
I installed “npm install mailparser” on a Docker container where my n8n is hosted.
It would be a great help from you.
Hey @Hellboy hope all is well, how did you install it?
I tried myself and it works just fine.
docker exec -it --user root n8n /bin/sh
cd .n8n
npm install -g mailparser
then
@jabbson Thanks for the help, I really appreciate your support.
Still I am getting error, I tried the way you suggested. Please check the below screenshots. After installing mailer parser, I restarted the container as well.
{
“errorMessage”: “Cannot find module ‘mailparser’ [line 1]”,
“errorDescription”: “VMError”,
“errorDetails”: {},
“n8nDetails”: {
“nodeName”: “Code1”,
“nodeType”: “n8n-nodes-base.code”,
“nodeVersion”: 2,
“n8nVersion”: “1.103.2 (Self Hosted)”,
“binaryDataMode”: “default”,
“stackTrace”: [
“VMError: Cannot find module ‘mailparser’”,
" at Resolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/resolver.js:126:9)“,
" at Resolver.resolve (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/resolver.js:121:15)”,
" at resolve (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/nodevm.js:317:21)“,
" at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/bridge.js:490:11)”,
" at requireImpl (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/setup-node-sandbox.js:90:19)“,
" at require (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/setup-node-sandbox.js:171:10)”,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected] _asn1.js@5_1af219c3f47f2a1223ec4ccec249a974/node_modules/n8n-nodes-base/dist/nodes/Code:1:116",
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected] _asn1.js@5_1af219c3f47f2a1223ec4ccec249a974/node_modules/n8n-nodes-base/dist/nodes/Code:3:2",
" at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/bridge.js:490:11)“,
" at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/nodevm.js:497:23)”
]
}
}
This could actually be the problem, depending on how you restarted the container.
Containers are ephemeral entities, and if you down and up your infra it creates a new one, which doesn’t have the parser installed.
@jabbson
This time I tried without restarting the container after install the mailparser, still same error.
/home/node # npm install -g mailparser
changed 27 packages in 1s
11 packages are looking for funding
run npm fund for details
{
“errorMessage”: “Cannot find module ‘mailparser’ [line 1]”,
“errorDescription”: “VMError”,
“errorDetails”: {},
“n8nDetails”: {
“nodeName”: “Code1”,
“nodeType”: “n8n-nodes-base.code”,
“nodeVersion”: 2,
“n8nVersion”: “1.103.2 (Self Hosted)”,
“binaryDataMode”: “default”,
“stackTrace”: [
“VMError: Cannot find module ‘mailparser’”,
" at Resolver.resolveFull (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/resolver.js:126:9)“,
" at Resolver.resolve (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/resolver.js:121:15)”,
" at resolve (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/nodevm.js:317:21)“,
" at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/bridge.js:490:11)”,
" at requireImpl (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/setup-node-sandbox.js:90:19)“,
" at require (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/setup-node-sandbox.js:171:10)”,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected] _asn1.js@5_1af219c3f47f2a1223ec4ccec249a974/node_modules/n8n-nodes-base/dist/nodes/Code:1:116",
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected] _asn1.js@5_1af219c3f47f2a1223ec4ccec249a974/node_modules/n8n-nodes-base/dist/nodes/Code:3:2",
" at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/bridge.js:490:11)“,
" at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/nodevm.js:497:23)”
]
}
}
looks all good to me, did you make sure that mailparser is actually allowed to be executed?
On the instance I use it, I have added
NODE_FUNCTION_ALLOW_EXTERNAL=mailparser
and
N8N_REINSTALL_MISSING_PACKAGES=true => make sure the package is added if I update n8n.
to the Docker-ENV variables.
Hi @nabossha
Please check screenshots completely workflow.
I guess mailparser is working fine, check 3rd screenshot.
I copied your code from previous post to extract the email headers but I am getting error.
error details:
{
“errorMessage”: “Input cannot be null or undefined. [line 9]”,
“errorDescription”: “TypeError”,
“errorDetails”: {},
“n8nDetails”: {
“nodeName”: “Code2”,
“nodeType”: “n8n-nodes-base.code”,
“nodeVersion”: 2,
“n8nVersion”: “1.103.2 (Self Hosted)”,
“binaryDataMode”: “default”,
“stackTrace”: [
“TypeError: Input cannot be null or undefined.”,
" at module.exports (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/[email protected] /node_modules/mailparser/lib/simple-parser.js:7:15)“,
" at ReadOnlyHandler.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/bridge.js:490:11)”,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected] _asn1.js@5_1af219c3f47f2a1223ec4ccec249a974/node_modules/n8n-nodes-base/dist/nodes/Code:9:9",
" at new Promise ()“,
" at new localPromise (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/setup-sandbox.js:33:1)”,
" at parseEmail (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected] _asn1.js@5_1af219c3f47f2a1223ec4ccec249a974/node_modules/n8n-nodes-base/dist/nodes/Code:8:12)“,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected] _asn1.js@5_1af219c3f47f2a1223ec4ccec249a974/node_modules/n8n-nodes-base/dist/nodes/Code:31:27”,
" at /usr/local/lib/node_modules/n8n/node_modules/.pnpm/n8n-nodes-base@file+packages+nodes-base_@[email protected] _asn1.js@5_1af219c3f47f2a1223ec4ccec249a974/node_modules/n8n-nodes-base/dist/nodes/Code:45:2",
" at VM2 Wrapper.apply (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/bridge.js:490:11)“,
" at NodeVM.run (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/@[email protected] /node_modules/@n8n /vm2/lib/nodevm.js:497:23)”
]
}
}
Can you please post the code from the Code2 Code Node?
I expect this could be happening because you read the input as
const emailContent = $input.first().json['data'];
but I do not see the data property in the input. Instead I see emlText. Please check that. From what it appears to be, when you call SimpleParser on line 9 you pass the output of the previous node (but when you extract that output you extract ‘data’ instead of ‘emlText’, which causes the content to be empty and this is why you get the error Input cannot be null or undefined.
1 Like
@jabbson you are correct, I was calling wrong, I updated code (‘data’ instead of ‘emlText’) and it worked fine.
1 Like
Perfect! Thanks for confirming. If this helped you solve your problem, kindly mark the answer as solution. Thank you.
Cheers!
@nabossha Thanks for the support, I tried your method as well and it worked fine and even better than mine. I am gonna implement your method.
1 Like
system
Closed
August 5, 2025, 8:31pm
14
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.