DEV Community

Cover image for The Inbox Beast: an n8n workflow sorts the inbox and feeds a beast
Daniele Michelin
Daniele Michelin

Posted on Originally published at daniele-michelin.com

The Inbox Beast: an n8n workflow sorts the inbox and feeds a beast

Try it first: the Inbox Beast. One click, a few seconds, and the beast is there.

What you get

  • A beast in five stages: from egg to kraken, depending on its hunger. It has a mood and comments on the inbox.
  • Three columns: Do (you must answer yourself), Delegate (someone on the team, by name) and Ignore (newsletters, sales pitches, anything already answered).
  • A report: three sentences about the state of the mail and one concrete tip.
  • Real entries in Nextcloud: up to five cards on the demo Deck board, a message in the Talk room and a Markdown file in the Outbox folder.
  • Two dials: “Answer the most important mails first” and “How long since you looked at the inbox?”. They simulate what would happen without changing anything.

The workflow

  • Webhook: receives a colour and two numbers. The page sends nothing else.
  • Fix the demo space: a Code node defines which file, which Deck board, which Talk room and which folder may be used. Every URL of the following nodes is checked against it.
  • Three requests in parallel: WebDAV fetches Inbox/inbox.json, the Deck API the board, a PROPFIND lists Outbox/.
  • Rules first: fixed rules sort every mail and give it a priority. The workflow therefore still works when the AI is down.
  • AI: gpt-oss-120b at IONOS corrects the sorting and writes the report, the quote and the tip. Every answer is validated: unknown categories, invented people and answers about mails that are already answered are dropped.
  • Compute hunger: a Code node, see below.
  • Clean up, then write: first the workflow deletes its own earlier cards (they carry a marker in the description) and the oldest reports, then it creates the new ones.
  • Result: posted to a PHP script with the real HTTP status codes of the writes. The page only says “created” when Nextcloud really answered 2xx.

How the hunger is calculated

Every unanswered mail counts with a weight: 8 for do, 5 for delegate, 1 for ignore. The weight grows with age by up to a factor of 4 (after seven days), so each mail counts weight × (1 + age in h / 48). The sum S is turned into a value between 0 and 100 percent: hunger = 100 × (1 − e^(−S/150)). The stages start at 10, 28, 48 and 70 percent.

The demo inbox holds 14 unanswered mails and the oldest client mail is 120 hours old. That gives 69 percent, a “Big beast”. Answer the three most important mails and hunger drops to 56 percent; with six mails it is 38 percent (stage Beast). Leave everything for three more days and it is 84 percent: kraken.

Safety

The workflow runs in a demo space of a real Nextcloud account: its own folder, its own Deck board, its own Talk room, invented data of the fictional Brightside Studio. It reads a single file and writes only to Outbox/, to one Deck stack and to one Talk room. The page limits the runs (20 seconds between runs, three per hour and visitor, 100 per day), and the workflow only deletes what it created itself. One limitation: the Talk room keeps its messages, the workflow does not delete them.

For your own inbox

Replace the node “Read: inbox.json” with IMAP or Gmail and map the fields id, from_name, from_email, subject, body, age_hours, answered. The Code node “Read the inbox” needs only those. The rules are keywords for an invented studio: for real mail you have to adapt them, and the AI sorting is a suggestion, not a verdict.

Build it yourself

The workflow as JSON contains only placeholders for address, user, Talk room and credentials. You need a Nextcloud with Deck and Talk, an app password as a Basic-Auth credential in n8n and an OpenAI-compatible credential for the AI (the workflow also runs without). Enter board id, stack id and room token in the first Code node. You cannot import the file as it is.


Originally published at daniele-michelin.com. More guides, free checks (SPF, TLS, headers) and an error-message lexicon: daniele-michelin.com/en/.

Top comments (0)