Automated Contact Database Builder from Gmail and AI - n8n Workflow

Use this sophisticated n8n workflow to enrich your contact database. It leverages Gmail history and GPT-5 Nano for precise extraction, supplemented by Brave Search API to find social media links and websites, outputting clean data to Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Sales and Business Development Teams needing to rapidly build and enrich lead lists.

  • Marketers seeking structured social media contact data for outreach.

  • Data Analysts and Researchers utilizing Gmail as a primary data source.

  • Users looking for advanced examples of how to combine LLMs, web search, and data parsing within an n8n environment.

Overview

Managing vast contact lists scattered across email threads can be inefficient. This powerful n8n workflow solves this by creating a highly structured, enriched contact database automatically. It starts by analyzing your Gmail sent items, identifying unique recipients, and then follows a dual-path extraction process. If a full conversation history exists, the content is analyzed by an AI model (like GPT-5 Nano) using the specialized Information Extractor n8n node for precise data scraping (phone, social links). If no history is found, the n8n workflow automatically derives a domain and uses the Brave Search API to find relevant contact pages, scraping the HTML for publicly listed social media and contact details. All gathered data is normalized and appended to a central Google Sheets database. This n8n templates offers a robust solution for contact data management.

How it Works

The process begins with the manual n8n trigger, initiating the data collection phase.


  1. Email Loading and Deduplication: The n8n workflow uses the Gmail n8n node to load all messages from the 'SENT' folder. It then extracts all 'To' and 'Cc' addresses, removes duplicates, and splits them into batches for individual processing.

  2. Path Selection (AI vs. Web Search):

Path A (AI Extraction): The n8n node 'GetInboxMessages' searches for existing conversation history with the current contact. If history is found, the entire thread content is passed to the LangChain Information Extractor n8n node, powered by the 'gpt-5-nano' OpenAI Chat Model. This model strictly follows a JSON schema to pull structured data (phone, website, social links), critically ignoring the data of the recipient.
Path B (Web Search): If no conversation history exists, the n8n workflow uses a Code n8n node ('MailParser') to derive a corporate website from the contact's email domain (excluding generic domains like gmail.com).

  1. Brave Search & HTML Scraping: If a valid domain is found, the 'SearchWebsite' n8n node (Brave Search) looks for URLs containing contact-related keywords. The subsequent 'GetHTML' n8n node scrapes the content of these promising contact pages. The 'HTMLParser' n8n node then applies advanced regex to extract specific social links (Instagram, Facebook, Bandcamp, etc.) from the scraped content.

  2. Data Aggregation and Finalization: Data from both Path A (AI Merge) and Path B (HTML Parser) is structured consistently.

  3. Database Write: The final, enriched contact record is written to the configured Google Sheets using the 'WriteToDB' n8n node, completing the execution of the n8n workflow.

Installation Guide

To deploy this comprehensive n8n workflow template, follow these steps:


  1. Import the n8n Workflow JSON: Copy the provided JSON data and paste it into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Google Sheets Setup: Create a new Google Sheet with columns matching the extraction schema: name, email, phone, website, facebook, instagram, spotify, youtube, linkedin, twitter, linktree, tiktok, soundcloud, bandcamp. Ensure you configure the 'WriteToDB' n8n node with the correct Spreadsheet ID and Sheet name.

  3. Credential Setup: This n8n workflow requires four critical credentials:

Gmail OAuth2: Used by 'LoadSentMessages' and 'GetInboxMessages'. Ensure it has access to view your sent and received emails.
OpenAI API: Used by the LangChain nodes for AI extraction.
Brave Search API: Used by the 'SearchWebsite' n8n node for targeted web searches.
Google Sheets OAuth2: Required for appending the final contact data.

  1. Execution: Once credentials are set and the Google Sheets n8n node is configured, click the 'Execute workflow' button to start the process.

Node Details

This n8n workflow relies on several powerful n8n node types:

Gmail (LoadSentMessages / GetInboxMessages):
Function: Loads all sent emails and later searches for specific conversation history based on the recipient's email.
Key Configuration: LoadSentMessages filters by the SENT label. GetInboxMessages uses an expression to filter by the current contact's email address (={{ $json.To }}).
LangChain Information Extractor (Information Extractor):
Function: Passes email content to the LLM (OpenAI) using a detailed system prompt and JSON schema to extract specific contact fields (phone, web, social links) reliably.
Key Configuration: Uses a highly customized system prompt instructing the model to ignore recipient data and return structured JSON.
Brave Search (SearchWebsite):
Function: Executes targeted web searches using the derived domain name, searching for contact-related pages.
Key Configuration: Query uses the derived website URL (={{ $json.website }}) and returns up to 3 results.
HTTP Request (GetHTML):
Function: Scrapes the HTML content of the contact pages identified by Brave Search.
Key Configuration: Dynamically pulls the URL from the cluster results.
Code (MailParser / HTMLParser):
Function: MailParser extracts basic contact data and intelligently derives corporate website domains, filtering out free providers (e.g., gmail.com). HTMLParser uses complex regex to reliably extract social media links from the scraped HTML content.
Google Sheets (WriteToDB):
Function: The final destination n8n node; it appends the complete, enriched contact record to the specified spreadsheet.

Related n8n Workflows

Free

Nodes: 16 Nodes
Updated: December 26 2025
View all
Created by
Václav Čikl
Václav Čikl

Featured*