I’ve been on an exhausting road of research, testing, and ChatGPT discussions trying to get this working.
Scenario
Users in the org can flag emails as suspicious, which then sends a copy of the flagged email as an attachment in an email to another mailbox. The suspect email is sent as an attachment to preserve the original headers.
Vision
Suspect emails can be analyzed in one of two ways:
- (Form Submission) The user can go to a n8n form and submit the email for analysis as a file.
- (Automated Screening & Analysis) n8n will monitor the suspect mailbox and automatically download the file and analyze it.
Progress
Right now, I’m just focused on getting the suspect email processed by eml-parser. So I’m only going so far as getting the proper output from eml-parser. I’ve completed this much on the Form Submission process. User goes to a site, uploads the file and then in the background the file gets submitted to eml-parser which does its thing.
Problem
On the automated screening and analysis flow, I’m stuck. I’ve got an IMAP node setup and it properly pulls in the email and its attachments. I’ve setup a code node to filter out all attachments except .eml files. Then the HTTP Request node and this is where I’m dead in the water. I’m not sure what the best way to give information, but if I don’t provide something, please ask.
IMAP Binaries from email
Code Node setup
let results = [];
for (item of items) {
for (key of Object.keys(item.binary)) {
if( item.binary[key].mimeType == 'message/rfc822' ) {
results.push({
json: {
fileName: item.binary[key].fileName
},
binary: {
file: item.binary[key]
}
});
}
}
}
return results;
Code Node Output
HTTP Request Node Configuration
Request Node Output
Hi @Grunticus,
The screenshots look good to me.
Just to confirm, are you able to successfully upload .eml and use your endpoint: http://eml-parser-service:3000/parse
outside of n8n, such as with cURL or Postman?
I actually did not try this as I don’t have the email parser exposed outside of the docker environment. However, my current workflow is split into separate paths, the IMAP upload and the file submission. The file submission path works passing the data along to the eml-parser endpoint.
I intended to unite the two at the first HTTP Request, but because something’s not working right with the IMAP node path, I split them out to troubleshoot.
1 Like
@Grunticus Thanks for this, it’s okay.
I have an observation, though I’m not sure if it will help or if it’s related to the issue.
In your code, you have this snippet for the file name:
fileName: item.binary[key].fileName
However, in your screenshot of the code node output, there is no File Name shown!
I would suggest either setting a file name explicitly or ensuring that the file has a name assigned.
That’s what I was actually looking at right now. I noticed all the other files had their filename, but not the .eml file. Is this something I can code into the IMAP node or do I need to do it at the code node that comes after?
you already try this in your code
results.push({
json: {
fileName: item.binary[key].fileName
},
lets see if it correctly prints the file name or what is wrong here
I mean, what is in the JSON tab outputs?
Fixed!
I’m leaning towards something in the code step that wasn’t processing the data properly. I had ChatGPT generate code (I don’t know JS or Python) that would filter out all files that were not .eml. This generated the below output:
When I went back and gave it the previously generated code and told it to generate a filename for anything that was missing one, the output looked like this:
The fact that the code block doubled in size (~20 lines to ~50 lines) makes me thing the initial code wasn’t right to begin with. Additionally, I can now download the output binary.
Now that it’s properly applying, the eml-parser call works perfectly.
I intend to do a write-up for this. In trying to find a solution, I found a lot of people asking the same thing about parsing .eml files. Involved some light customization of the docker compose file and setup of the .eml microservice.
1 Like
Interestingly, the fileName attribute is missing from the IMAP node, only for the .eml file. T
The JSON output doesn’t say anything about binary information. This is actually something that’s frustrated me about n8n. Binary field data isn’t in the JSON or Schema views and the BInary view gives you the ‘human readable’ version of the field.
Good find!
You could open a GitHub issue explaining this behavior in detail to find out if it’s intentional or actually a bug…