Skip to main content

Automatically process emails in n8n using AI

Need to keep an eye on important emails (like server outage alerts) and don’t want to miss a thing? This simple guide shows you how to set up an automated flow in n8n that:

  • Monitors an email inbox via IMAP

  • Uses an AI model to decide whether a message is important

  • And if it is, sends a Telegram notification with a short summary

In this guide, we’ll integrate n8n with FASTPANEL — used here as the IMAP mail server where mailboxes are created and managed.

Set up your mailbox (If you haven’t yet)

Before we jump into n8n, let’s make sure your email inbox is ready to go.

Follow this guide to create a new mailbox:

How to add a new mailbox in FASTPANEL

Once the mailbox is created:

  • Save the login and password — you’ll need them later when connecting it to n8n

  • You don’t need to set up anything else on the FASTPANEL side — you're done there!

Now, let’s move on and start building the automation in n8n.

Create a new workflow

First things first — we’ll create a new flow in n8n.

Open n8n and click "Create workflow" in the top-right corner

Create workflow

Tell n8n to watch your email inbox

We want n8n to check your email account for new messages.

Click "Add first step..."

Add step

Search for imap, and choose "Email Trigger (IMAP)"

Add Email Trigger

This will allow n8n to monitor incoming emails using IMAP.

Connect your email account

Let’s give n8n access to your mailbox.

Click "Create new credentials", fill in your email login info, and (if needed) enable "Allow Self-Signed Certificates". Give your connection a name so it’s easier to find later

Create new credentials

If you see "Connection tested successfully", you’re good to go

Connection tested successfully

Adjust trigger settings

One quick tweak before we move on.

In the trigger settings, change "Mark as read" to "Nothing", then click "Back to canvas"

Adjust trigger settings

Prepare your AI API key

We’ll be using OpenRouter to power the AI.

Go to OpenRouter, sign in, create an API key (ProfileKeysCreate API Key), and copy it — you won’t be able to see it again.

create an API key

Add the AI agent

Time to bring AI into the workflow.

Click "+", search for AI Agent, and add it to the canvas

AI Agent AI Agent

Then hit "Back to canvas".

Add an AI model

Let’s choose the brain behind the agent.

Click "+" again, search for OpenRouter Chat Model, and add it

Add model OpenRouter Chat Model

Create new credentials using your API key

API Key

Then pick a free model (you can type free to filter, for example, DeepSeek)

AI Model

Tell the AI what to look for

We’ll now teach the AI how to recognize important messages.

Click "Execute Workflow", send a test email to the address being monitored, and then double-click the AI Agent node once the email arrives

AI Model

Now let’s tell the AI what to do:

  • Set Source for Prompt to Define below
  • Under Prompt, choose Expression and drag in the textHtml variable
  • Click "Add option", select System message, and paste this:
You're an assistant that determines the importance of an email.
If the email mentions a server being unavailable, return a short summary.
Otherwise, return "false".

AI config

Click "Back to canvas" to continue.

Add a check for important emails

We only want to take action if the email really matters.

Add an If node

IF Node

Set the condition:
If the AI output is not equal to false

condition

Send the Telegram notification

Let’s get that message delivered straight to you.

From the true output of the If node, add a TelegramSend a text message node

Telegram

Create new credentials:

AI’s output

Check your full workflow

At this point, your full setup should be visible on the canvas.

It should include:

  • Email trigger

  • AI analysis

  • Condition check

  • Telegram message

Workflow

Test everything

Let’s make sure it all works.

Click Execute Workflow and send another test email. If everything’s set up right, you should see it waiting for a trigger.

Workflow

If all is working, you’ll get a notification in Telegram, summarizing the message.