MIME message parser … parse mail into subject, body text, html, attachments, etc

Hi there,

I’m looking for a node that can take in a MIME message and split this into an JSON object with subject, body, html, from, etc. as well as the individual attachments.

Basically, what I’m looking for is the IMAP Email node, but instead of waiting for a mail message, actively feeding the MIME message into this node.

And if this does not exist yet, would anybody be interested to help me develop such a node?

Thanks in advance and best regards - Dick

If I understood correctly I do not think you even need to create a node to do this. Just import Nodemailer in a function node (you need to set an env variable to be able to do so) and use the simpleParser method.

Hi @RicardoE105 , thanks and uh … since I’m relatively new to n8n, does this means that I’ve got to ad NODE_FUNCTION_ALLOW_EXTERNAL to the environmental variables (/.env) file? And that I that have to start with JavaScript code in the function node with

const simpleParser = require('mailparser').simpleParser;

And would have some idea how much time/effort it would take to built a n8n node to do this?



I would say like 45 to 60 minutes. But that depends on how familiar you are with node development.

@RicardoE105 just tried this in the Desktop version on macOS and get the following error:

ERROR: Access denied to require ‘mailparser’

Any idea what I might be missing?

Hey @dickhoning,

Try NODE_FUNCTION_ALLOW_EXTERNAL=mailparser and see if that does the job.

1 Like

Hi @Jon this and restarting the Desktop App dit the trick. Thanks!

1 Like

Hi @dickhoning,

I forgot to mention the restart :smile: Glad to hear you have it working now though :+1:

now I’ve starting to get simpleParser to work :slight_smile:

The only thing I haven’t figured out yet, is how to get the attachments. Since I’m a very simple FileMaker Developer and not used to hardcoding, I’m probably overlooking something very simple.

This is my code so far:

The TestMIME without attachments works fine, but the Test MIME with Attachment returns a whole lot of text. And if you want to change from Object to JSON, it hangs-up the system.

And this is the relevant section of the documentation from NodeMailer …

attachment object

Any help would be really appreciated as I’ve got the feeling that I’m nearly there …

found it :grin: … created a Function Item with the following code:

const buf = Buffer.from(item.attachments[0].content.data).toString('base64');

const result = [];

result.push({ base64encoded:buf })

return result;

Now I just have to figure out how to convert this to a Function that process all the attachments …

And I finally figured it out … with the help of some of the kind people in the n8n community as well as the apparently limitless amount of information in this forum.

My working workflow with simpleParser now looks as follow:

This workflow contains a separate branch for testing.

The whole concept is to feed in the MIME text of an email message which then gets converted to a JSON array with all the relevant data, such as from, to, date, subject, body, html, messageId and attachments. It also convert the attachment buffers into Base64encoded text.

I already build something in FileMaker year’s ago, but this has become so complicated that it is difficult to maintain.

Since I’m fairly new to n8n and still have to get my head around a few basic concepts, this flow may be more complicated than necessary. So please do not hesitate to give me feedback :grin:

And this is the code …

1 Like

After further implementation in my FileMaker workflow, I found out that I had not taken into account messages without attachments. Here’s the workflow that does:

Please note: this workflow uses simpleMailer, so you’ll need to ad the following to your environments file in order to make this work:


Another way to spent a windy and rainy Sunday afternoon :grin:

Would the mailparser work with cloud? Or is this only localhost functionality. Anything similar that would work on cloud or am I stuck regex’ing?

Hi @Philip_Wiggins , as far as I know, mail parser is not available with cloud.