Gmail Metadata Extractor and Google Sheets Logger - n8n Workflow

Use this powerful n8n workflow to automatically extract sender name, email, subject, and body from new Gmail messages. This n8n workflow cleans the data and logs structured records directly into Google Sheets, perfect for lead tracking and support logging.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Marketing teams who need to capture contact form submissions sent via email.

  • Customer support operations requiring a centralized log of all incoming inquiries.

  • Business analysts needing clean, structured email data for reporting.

  • Users looking for robust n8n templates for advanced email processing.

Overview

Handling incoming email data often presents challenges due to inconsistent formatting. A simple integration might fail to correctly parse sender names when they appear as 'Name ' or are embedded within the message body itself. This n8n workflow solves this by utilizing a sophisticated custom script to intelligently parse and standardize data received by the Gmail n8n trigger.

This specific n8n workflow ensures that every important piece of metadata—including name, email, subject, message body, and a timestamp—is reliably extracted, cleaned, and organized. The result is a clean, automated stream of customer interaction data logged directly into your chosen Google Sheet, saving significant manual labor and improving data quality across your organization. It stands as a powerful example of what is achievable using core logic within an n8n node structure.

How it Works

This automation functions entirely on new email arrivals, leveraging a powerful sequence of n8n nodes:


  1. Trigger on New Email: The n8n workflow starts with the Gmail n8n trigger. This n8n trigger node is configured to poll your Gmail inbox every minute for new messages.

  2. Intelligent Data Extraction (Code n8n node): Upon receiving an email, the flow passes the raw message data to a Code n8n node. This node executes custom JavaScript designed to perform advanced data cleaning. It looks for the subject and body across multiple possible fields ($json.subject, $json.snippet, etc.). Crucially, it attempts to extract the sender's full name, prioritizing names found in the message body (e.g., 'I am John Doe') over header names, ensuring the most useful contact information is captured.

  3. Data Structuring (Set n8n node): The output from the Code n8n node (clean name, email, subject, message, timestamp) is then mapped into standardized, user-friendly field names (e.g., 'Full Name', 'Email Address'). This prepares the data specifically for the Google Sheet structure.

  4. Logging to Google Sheets: Finally, the Google Sheets n8n node appends a new row to the designated spreadsheet. This action uses the newly structured fields to create a clean, timestamped record of the incoming email, completing the seamless n8n workflow.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON code and paste it directly into your n8n instance using the 'Import from JSON' option.

  2. Configure Gmail Credentials: Locate the starting Gmail n8n trigger node. You will need to set up or select an existing OAuth2 credential to grant n8n access to your Gmail account.

  3. Configure Google Sheets Credentials: Select the Google Sheets n8n node ('Append row in sheet'). Set up or select an OAuth2 credential that allows n8n to write to your Google Drive.

  4. Specify Target Sheet: Within the Google Sheets n8n node parameters, select the specific Google Sheet Document ID and the Sheet Name where you wish to log the data. Ensure the header row of your sheet matches the mapped fields: Tme, Name, Subject, Email Address, and Body of the email.

  5. Activate the n8n workflow: Once credentials and sheet details are correctly configured, set the n8n workflow to 'Active' to begin monitoring your inbox.

Node Details

This n8n workflow relies on four core n8n nodes:

Gmail Trigger n8n trigger:
Function: Serves as the starting point, triggering the n8n workflow upon the arrival of any new email.
Key Configuration: Set to poll Gmail every minute for immediate response to new messages.

Code n8n node:
Function: Executes custom JavaScript to intelligently extract and clean metadata. This is the heart of the n8n template's power, handling variable input formats for subject, body, and sender details.
Key Configuration: Script logic includes fallback values ('No Subject') and regex matching to accurately extract names from both email headers and message content (e.g., matching the pattern 'I am (.?) from').

Edit Fields (Set) n8n node:
Function: Standardizes the data structure outputted by the Code n8n node, renaming internal keys (like name) to practical column headers (like Full Name) ready for the spreadsheet.
Key Configuration: Explicitly maps and sets five fields: Full Name, Email Address, Subject, Body of the email, and Time.

Append row in sheet (Google Sheets) n8n node:
Function: Takes the cleaned, structured data and appends it as a new row in the specified Google Sheet.
* Key Configuration: Operation is set to appendOrUpdate. Input values are mapped directly from the Set n8n node's output, ensuring data lands in the correct spreadsheet columns.

Related n8n Workflows

Free

Nodes: 5 Nodes
Updated: December 26 2025
View all
Created by
Mohammed Abid
Mohammed Abid

Featured*