Label New Emails in Gmail
Automate email labeling in Gmail to keep your inbox organized by applying the right labels instantly as new messages arrive.
Last updated
October 1, 2025
Connectors used
Tags
Key Takeaways
- Automatic labeling on arrival - New emails are labeled as soon as they hit your inbox, with no manual sorting needed.
- Uses your existing Gmail labels - The workflow reads your current label structure and assigns emails to those labels.
- Triggered by new emails - A polling trigger watches your Gmail inbox and kicks off the workflow when new messages arrive.
- Filters out unwanted senders - A code node lets you exclude specific senders from processing before labels are applied.
What This Workflow Does
This workflow automatically labels incoming Gmail emails by combining a new-email trigger with AI-powered label assignment. When a new email arrives, the workflow fetches recent emails and your existing Gmail labels, then applies the appropriate labels to each message based on its content. It runs continuously in the background so your inbox stays organized without you doing anything.
Use cases:
- Keeping a busy inbox organized by auto-sorting emails into categories like work, finance, or newsletters
- Ensuring important emails from specific senders always get flagged with the right label
- Maintaining a consistent labeling system across a shared Google Workspace inbox
How It Works
| Step | What Happens |
|---|---|
| 1. New Email Trigger | A polling trigger detects new emails arriving in your Gmail inbox. |
| 2. Find Emails | Fetches the last 100 emails from Gmail. |
| 3. Filter Emails | A code node removes unwanted senders from the list. |
| 4. Flatten Results | A transform node flattens the email data for processing. |
| 5. List Labels | Retrieves all existing labels from your Gmail account. |
| 6. Extract Label Info | A code node formats label IDs and names into a clean list. |
| 7. Merge | Combines the filtered emails with the available labels. |
| 8. Attach Labels | A code node maps the full set of possible labels onto each email. |
| 9. Add Labels | Applies the appropriate labels to each email in Gmail. |
Workflow Nodes
| Node | Role |
|---|---|
| Gmail New Email Received | Polling trigger that fires when new emails land in the inbox |
| Gmail Find Email | Queries Gmail for the last 100 emails |
| Code (Filter) | Filters out specific senders you want to exclude |
| Transform | Flattens nested email results into a single list |
| Gmail List Labels | Fetches all available Gmail labels |
| Code (Extract Labels) | Extracts label IDs and names into a structured format |
| Merge | Combines email data with label data |
| Code (Attach Labels) | Adds the full list of possible labels to each email object |
| Gmail Add Label to Email | Applies the chosen labels to each email |
Setup Instructions
- Add the "Label New Emails in Gmail" template to your Needle workspace.
- Connect your Gmail account by creating a Gmail connector in Needle.
- Select your Gmail connector in the Find Email, List Labels, and Add Label to Email nodes.
- Optionally, update the filter code node to exclude or include specific senders.
- Publish the workflow so the trigger runs automatically.
Customization
| What You Can Change | How |
|---|---|
| Sender filtering | Edit the code node to change which senders are excluded from labeling |
| Number of emails fetched | Change the maxResults value in the Find Email node (default is 100) |
| Label assignment logic | Update the instructions in the Add Label to Email node to adjust how labels are chosen |
| Inbox scope | Modify the trigger's label filter to monitor specific Gmail labels instead of the full inbox |
FAQ
Q: Does this workflow create new labels in Gmail? A: No. It uses your existing Gmail labels. You need to create the labels you want in Gmail first, and the workflow will assign emails to them.
Q: How quickly are emails labeled after they arrive? A: The trigger uses polling, so there may be a short delay depending on the polling interval. It is not instant but typically runs within minutes.
Q: Can I use this with Google Workspace? A: Yes. The Gmail connector works with both personal Gmail accounts and Google Workspace accounts.
Q: What happens if an email matches multiple labels? A: The Add Label to Email node can apply multiple labels to a single email based on the analysis of its content.
Want to showcase your own workflows?
Become a Needle workflow partner and turn your expertise into recurring revenue.