What should have been a very quick 10-minute n8n workflow ended up being a substantial amount of work.
Search for "IMAP" in the n8n node list and you'll be surprised to see only one node to trigger a workflow from a new IMAP email, with no additional node for further manipulation.
Now, try that node, and you'll be even more surprised: the node doesn't even work at all. I tried to debug and understand if I was doing anything wrong, only to end up on some thread explaining that, apparently, in test mode, there is no chance of making it work. What a bummer.
No efficient trigger, no IMAP operation. Time for me to solve that. All my emails are on my personal servers and not on Gmail, so I need to build a sustainable solution.
I don't know about you, but I have personally been using an email client on my phone and computer for years. They detect emails instantly, not like a recurring poll that regularly checks for new emails, but real, instant notifications. That will be my first requirement.
The best way to activate an n8n workflow is through a webhook. Just hit your n8n server on any active webhook, and the workflow will instantly trigger. Webhooks are perfect for this use case. They don't waste any resources and will get the job done as soon as you give them some work to do.
So the idea is simple: monitor an IMAP mailbox in real time and, as soon as an email is received, read it, serialize it, and forward the content in a neatly formatted JSON payload to the n8n webhook endpoint.
To finalize the solution, we also need an API that n8n can interact with in order to manipulate emails in your inbox and perform basic operations.
I tried to keep the project as simple as possible while maintaining very resilient code against failures. And I think I've nailed it.
The final solution consists of two Docker containers.
The role of this container is to listen to your inbox and forward everything to your n8n webhook in real time. It records every email UID into a tiny local database to avoid resending. All emails will be instantly marked as read. You can disable attachment forwarding.
Your n8n webhook will receive data formatted as follows:
{
"uid": "1809",
"subject": "Your invoice is ready",
"from": "billing@example.com",
"to": "filter@mydomain.com",
"date": "2025-01-15T14:32:00",
"text_body": "Email text content...",
"html_body": "Email html content...",
"attachments": [
{
"filename": "invoice.pdf",
"content_type": "application/pdf",
"data": "base64 encoded content"
}
]
}
The role of this container is to provide a local API on your server where you can easily manage your emails through IMAP.
A list of available endpoints:
GET /health
GET /mailboxes
GET /messages
GET /messages/{uid}
PATCH /messages/{uid}/read
PATCH /messages/{uid}/unread
PATCH /messages/actions/read-all
DELETE /messages/{uid}
With these two containers, I can finally do what I initially wanted: filter and process emails.
The workflow is fairly straightforward:
The first container, imap2webhook, forwards every email to my n8n workflow.
A switch filters (currently) 2 different senders.
Based on the sender, the email content is extracted.
If the email was not from one of the 2 specified senders, it is marked back as "Unread."
Otherwise, once the data has been extracted, the email is deleted.
I hope these two tools will be helpful. If you would like to see them evolve, or if you spot a bug, feel free to contact me or open a bug report on GitHub.
Copyright 2026 © All rights reserved.
Copyright 2026 © All rights reserved.