Search in attachment content - outlook

My problem is that I receive two emails from an external company with attachments with the extension html. The only thing they have in common is in the middle of the file, unfortunately we can’t change that to be in the body/title as well.

I would like attachments to be searched based on a common value in the middle of the file and then forwarded to the intended recipient.
Is it even possible to do something like this?

Information on your n8n setup

  • n8n version: 0.198.2
  • Running n8n via desktop app

Hi @Wiktoria, I believe this would be possible using a logic like below:

Here I am first getting all unread messages with attachments, then listing their attachments, checking if they are HTML files, if so download them, parse them and finally check if they contain the text I am looking for:

In this case I am looking for <h1>foo</h1> but you can of course replace that as needed :wink:

Let me know if this is what you’re looking for!

Hi,
This is exactly what I was looking for!
Thank you very much for your help. :smiling_face:
I only have a problem with downloading attachments, I get the following message:
ERROR: The resource you are requesting could not be found
The specified object was not found in the store.

@MutedJam
Now, i have diffrent error :sweat_smile:

obraz

I came up with it like this, now i just have a problem with sending this file in html form to the recipient

Hi @Wiktoria, I am so sorry - the paired items functionality I have used here might not be available in the desktop app yet since it’s usually a few versions behind, which is why you would be seeing this error message :frowning:

Is there a chance you can use docker (docker run -it --rm -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n:0.203.1) to run n8n? If not, just let me know and I’ll have another look with the desktop app in mind once I have a bit of time.

Just heard that we’re looking to publish a new version of the desktop app next week, so if using docker is not an option it is probably worth waiting for that.

Thanks for your reply @MutedJam !
I will wait for the new version of the app
What I sent above works, it searches for what I need from the document. Is it possible to send this html file to a specific recipient now?

I ended up with something like this, it works ALMOST as it should.
The only problem I encountered was sending this message multiple times, as many times as I have unread messages in my inbox.

Can you help me? :sweat_smile:

1 Like

I can also use item list, but then I need a trigger that starts after receiving the message, is it possible for the messages to be read after saving the file to disk?

Hi @Wiktoria, it seems like more recent n8n versions don’t let me add attachments to draft messages anymore. So, while I previously suggested upgrading, you might want to hold off with that for a bit :frowning:

On the actual problem, I think something like below should do the job, provided you fetch only 1 message at a time whenever your workflow runs. To achieve this, just set limit to 1 when fetching your unread messages:

Workflow:

This adds both example attachments to one message:

image

The key here is using the Execute Once setting when creating the draft message, to prevent multiple messages from being created:

image

When adding the attachments, I am then using an expression like {{ $("Create draft message").first().json.id }}. The .first() part makes sure that I am always using the ID of the first (and only) draft message.

Hope this helps! Let me know if you have any questions on this.