Build an AI inbox assistant that tells you what matters
Everything you need to build the workflow: pictures, settings, and code. It checks your Gmail inbox every minute, lets an AI pick the important emails, and sends them to Discord as colored tiles.
#email-alerts
How the workflow runs
Data flows left to right through eight nodes. The AI Model plugs in underneath node 5 and gives it the brain.
- Schedule TriggerStarts on a timer
- CodeSets the new-email window
- GmailReads unread inbox mail
- AggregateCombines emails into one list
- Basic LLM ChainAI flags important emails
- AI Model (Qwen)Connects under node 5
- CodeBuilds the Discord tiles
- HTTP RequestNotifies on Discord
Access the platform
Three quick steps to get your own n8n workspace.
Create your account
- Go to www.aixworkspace.net.
- Click Access Platform, then scroll to Create your AIX Workspace Account.
- Enter your Full name and Email address, choose Individual, and click Create My Account.
Get your credentials from the email
You will get an email from register@aixworkspace.net with your n8n login, your PostgreSQL details, and your AI model details (Base URL and API key).
Log in to n8n
- Click the Sign-in URL in the email and log in with the email and password.
- You are now on the n8n dashboard, ready to build.
Build the workflow
Click Create Workflow, then add these 8 nodes from left to right. The AI Model node connects underneath the LLM Chain node.
Schedule Trigger
Search “Schedule Trigger” · starts the workflow on a timer
- Trigger Interval
- Every 1 minute (for testing)
Code: Get new-email window
Search “Code” · looks back only at new emails
Paste this code
const staticData = $getWorkflowStaticData('global');
const now = new Date();
const since = staticData.lastCheck ||
new Date(now.getTime() - 24 * 60 * 60 * 1000).toISOString();
staticData.lastCheck = now.toISOString();
return [{ json: { since } }];Gmail: Read Inbox
Search “Gmail” · reads new unread emails (read-only)
First: connect your Gmail
- Go to console.cloud.google.com/auth/clients. Click Create client, choose Web application, and name it (for example n8n).
Google Cloud → Clients. Click Create client and choose Web application. - In n8n, open the Gmail node and create a new credential (Gmail OAuth2). Copy the OAuth Redirect URL shown at the top.
The n8n Gmail credential: copy the OAuth Redirect URL, and later paste your Client ID and Secret here. - Open your new client in Google. Under Authorized redirect URIs, paste that URL and save.
Paste the redirect URL under Authorized redirect URIs. The Client ID is on this same page. - Copy the Client ID (on the client page) and the Client Secret (in the Client secrets section).
Client secrets: copy the Client Secret (you see it only when it is created). - Paste the Client ID and Client Secret into the n8n credential.
- Add yourself as a test user: in Google go to Audience → Test users → Add users, and add your Gmail address.
Audience → Test users: add your own Gmail as a test user, or sign-in will be blocked. - Enable the Gmail API. In Google Cloud, open APIs & Services → Library, search for Gmail API, and click Enable (direct link: console.cloud.google.com/apis/library/gmail.googleapis.com). Make sure your own project is selected at the top.
- Click Sign in with Google and allow access.
Then: the node settings (after you are connected)
- Operation
- Get Many
- Return All
- Off · Limit: 50
Under Filters, click + Add Filter and add these two filters:
- Label Names or IDs: add INBOX and UNREAD (two labels). This reads only unread inbox mail.
- Received After: set it to {{ $json.since }}. This is the time from node 2 (the 24-hour window, then the last check), so it only gets new emails.
Aggregate: Combine emails
Search “Aggregate” · puts all emails into one list
- Aggregate
- All Item Data (Into a Single List)
- Put Output in Field
- emails
Basic LLM Chain: Flag important
Search “Basic LLM Chain” · the AI picks the important emails
Set the Text field (the prompt) to
You are the user's email triage assistant. For each email you get the
sender, the subject, and the body. Judge each email by its real meaning.
Return ONLY the emails that are IMPORTANT - ones that truly need the
user's attention or an action: a real person or client writing directly,
a real job or business opportunity, money, invoices or payments, meetings,
deadlines, approvals, or account and security matters (for example an OTP
the user requested, or an access request).
Ignore routine or promotional mail - newsletters, marketing, sales and
offers, social media or LinkedIn notifications, job-alert digests, order
or shipping updates, routine login alerts, and automatic no-reply notices.
The 'from' field has the sender name and email together - split it into
sender_name and sender_email.
Give each important email a priority:
- "high": urgent, act soon (money, security, urgent client)
- "medium": important but not urgent
- "low": good to see but minor
Output ONLY valid JSON. No extra words, no markdown. Use this shape:
[{"sender_name":"","sender_email":"","subject":"",
"summary":"one short line on what the email is for","priority":"high"}]
If no email is important, output exactly: []
Emails to check (JSON):
{{ JSON.stringify(($json.emails || []).map(e => ({ from: (e.from &&
e.from.text) ? e.from.text : (e.From || e.from || ''), subject: e.subject
|| e.Subject || '', body: (e.text || e.snippet || '').toString()
.replace(/\s+/g,' ').slice(0, 800) }))) }}AI Model (Qwen)
Add under node 5 · Search “OpenAI Chat Model” · the AI brain
- Credential
- Your AI model credential (Base URL + API key from the email).
- Model
- qwen3.8-27b
Code: Build Discord tiles
Search “Code” · turns the AI result into colored tiles
Paste this code
// Read the AI output (a JSON array of important emails).
let raw = ($json.text || '[]').toString();
let emails = null;
try { const v = JSON.parse(raw); if (Array.isArray(v)) emails = v; } catch (e) {}
if (!emails) {
const s = raw.indexOf('[');
const en = raw.lastIndexOf(']');
if (s !== -1 && en > s) {
try { const v = JSON.parse(raw.slice(s, en + 1)); if (Array.isArray(v)) emails = v; } catch (e) {}
}
}
if (!emails) emails = [];
const meta = {
high: { color: 16721920, tag: 'High' }, // red
medium: { color: 16776960, tag: 'Medium' }, // yellow
low: { color: 3066993, tag: 'Low' }, // green
};
const embeds = emails.slice(0, 10).map(function (e) {
const m = meta[(e.priority || 'medium').toString().toLowerCase()] || meta.medium;
const from = ((e.sender_name || 'Unknown') + ' | ' + (e.sender_email || '')).slice(0, 1024);
const about = ((e.summary || '').toString().slice(0, 1024)) || '-';
return {
title: (e.subject || '(no subject)').toString().slice(0, 256),
color: m.color,
fields: [
{ name: 'From', value: from },
{ name: 'What it is about', value: about },
{ name: 'Priority', value: m.tag, inline: true },
],
};
});
if (embeds.length === 0) { return []; }
return [{ json: { payload: { content: 'Important emails to review', embeds: embeds } } }];HTTP Request: Notify on Discord
Search “HTTP Request” · sends the message to Discord
First: set up Discord and get the webhook URL
- Download Discord: open the Microsoft Store, search for Discord, and click Get to install.
- Open Discord and sign up for an account (or log in if you already have one).
- Create your own server: click the + in the left sidebar, choose Create My Own, and give it a name.
- Create a text channel for the alerts: click the + next to Text Channels, choose Text, and name it email-alerts.
- Open the channel settings: hover the channel, click the gear icon (Edit Channel), then go to Integrations → Webhooks.
- Click New Webhook, then click Copy Webhook URL.
- Paste that URL into the URL field of this node.
Then: the node settings
- Method
- POST
- URL
- Your Discord channel webhook URL (from the steps above)
- Send Body
- On · Body Content Type: JSON · Specify Body: Using JSON
- JSON
- {{ JSON.stringify($json.payload) }}
You will see your final workflow like this
When you finish, your workflow should look like this. The node names may be the default ones (Code, Code1, and so on); that is fine.
Credentials you need
Have these three ready before you start building.
Gmail
A Google OAuth login (Client ID and Secret) so n8n can read your inbox.
AI Model
The Base URL and API key from your welcome email.
Discord webhook
The webhook URL of the channel where alerts should go.
Tile colors
The color of each tile shows how important the email is. You can change these numbers in node 7 (the “meta” part).
- Color
- Bright red
- Hex
- #FF2800
- Number (code)
- 16721920
- Color
- Yellow
- Hex
- #FFFF00
- Number (code)
- 16776960
- Color
- Green
- Hex
- #2ECC71
- Number (code)
- 3066993
Test and turn on
- Send yourself an email that looks important (for example, a client asking you to reply by tomorrow).
- Click Execute workflow and check your Discord channel for the colored tiles.
- When it works, turn the Active switch (top-right) ON so it runs every minute by itself.