Automatically Label Incoming Emails with AI
IN THIS ARTICLE
If you receive a high volume of emails in Gmail, sorting them into the right labels manually is a constant chore, especially when messages come from different senders, cover different topics, and need to go to different people or workflows.
AI can read each email and decide which label fits — but you need something to trigger that analysis automatically.
Albato handles this for you. Every time a new email arrives, it's sent to OpenRouter for analysis and labeled in Gmail based on the AI's response.
In this guide, we'll set up an automation that analyzes incoming emails with AI and assigns the right label in Gmail. Follow the steps below to set it up.
Before you start
You need an active OpenRouter account. Register at openrouter.ai and make sure you have API access.
You also need to set up labels in your Gmail account — the same labels you'll use for classification. Give them names, colors, and any other settings you prefer. The result should look like this.

Connecting the apps
In Albato, connect the services you'll use:
- Connect Gmail
- Connect OpenRouter
Creating the automation
Go to the Automations tab and click Create new automation.

Click on the first step to add the trigger. Select the Gmail service, choose the New Email event, and select the connection you created. Click Continue.


Now add the next step — the AI request. Click the + icon to add an action.

Select the OpenRouter service, choose the action, and select the connection. Click Continue.

Configure the AI query field. Use a prompt like this:
Analyze the text "" and assign one of the labels — Family, Finance, Shopping, Travel, Medical, Friends, Newsletters, Subscriptions — in one word.
In the highlighted part, list your Gmail labels. Between the quotes, insert the email body parameter from the trigger.

Select the AI model you want to use.

Mapping AI output to Gmail labels
To apply the correct Gmail label, you need to match the AI's text response to the actual label ID in Gmail. Use the Table Replacement tool for this.
Add it as the next step.


Configure the tool. The label IDs you need for matching can be found in your Gmail connection settings in Albato.

The configured mapping should look like this.

Add all your labels and an Otherwise fallback value.

Applying the label
Add the final action step — applying the label to the email.

Select the Gmail service and the Add label to email action.

Click Continue and configure the step. Map the message ID from the trigger and the label ID from the Table Replacement result.

Click Save, then click Start to activate the automation.
Here is how the full automation looks in Albato.

Now every incoming email will be automatically analyzed by AI and assigned the correct label in Gmail. If you have any questions, contact our support via chat.
Did this answer your question?