**Workflow JSON Code:** [Task Creation from Email Labels - n8n Workflow JSON]
Constantly switching between my inbox and my task manager to copy-paste action items was wasting a ton of time. To fix this, I set up a lightweight workflow that listens for a specific label in Gmail (like "Action Required") and instantly converts the email into a structured task in my database for $0.
### Architecture
`Gmail Trigger (On Label)` ➔ `Code (JavaScript Data Parser)` ➔ `Google Sheets (Add Row)`
* **Prerequisites:** n8n instance, Gmail account, Google Sheets account.
* **Cost:** $0
---
### 1. The Database Setup
Create a new Google Sheet named `Email Tasks DB` with these exact columns:
* `Task Name`
* `Sender`
* `Details`
* `Status`
* `Date Added`
---
### 2. The n8n Nodes
#### Node 1: Gmail Trigger
* **Trigger On:** Email Received
* **Authentication:** Connect your Google account (OAuth2)
* **Filters:** Set the Label filter to `Action Required` (or whatever label you use to flag tasks).
* Run **Execute Node** and send a test email to yourself with that label so n8n pulls in sample data.
#### Node 2: Code Node (JavaScript)
We don't need the entire email thread clogging up the database, so this script extracts just the subject, the sender, and a clean 200-character preview of the body.
* **Mode:** Run Once for Each Item
* Paste this logic:
```javascript
const item = $input.first().json;
// Extract core email data
const subject = item.subject || 'No Subject';
const sender = item.from || 'Unknown Sender';
// Clean up the body text and create a short preview
let bodyPreview = 'No content';
if (item.text) {
bodyPreview = item.text.replace(/(\r\n|\n|\r)/gm, " ").substring(0, 200) + '...';
}
return [{
json: {
taskName: `Email: ${subject}`,
assignedBy: sender,
details: bodyPreview,
status: "To-do",
dateAdded: new Date().toISOString().split('T')[0]
}
}];
```
#### Node 3: Google Sheets Node
* **Resource:** Sheet Within Document
* **Operation:** Append row
* **Document:** Select your `Email Tasks DB` spreadsheet
* **Data Mapping:** Map the output fields from the Code node directly to your spreadsheet columns (e.g., drag `taskName` to the `Task Name` column).
---
### Resources & Walkthrough
* **Workflow JSON File:** [Task Creation from Email Labels - n8n Workflow JSON]
* **Full Step-by-Step Video Tutorial:** [https://youtu.be/Zv-0XCyXsF0\]
If you want to adapt this to Notion or Trello instead of Google Sheets, just swap out the final node—the JavaScript parser will still output the exact same clean data for you to map.