Automate B2B lead generation & email campaigns with Google Maps, SendGrid & AI
๐ Overview
This n8n-powered workflow automates the entire lifecycle of lead generation and email workflows/campaign. It combines six specialized workflows into one seamless system that scrapes fresh leads, sends personalized emails, tracks engagements, detects replies, classifies responses, handles follow-ups, and keeps a live CRM updated โ all in one loop. Designed for B2B cold outreach and follow-up nurturing, this system integrates with Apify, Google Sheets, SendGrid, Gmail, and OpenAI for AI summarization and real-time alerts.
๐ง What It Does
This workflow automates the entire lifecycle of B2B cold campaign. It:
- Scrapes targeted leads directly from Google Maps (via Apify).
- Extracts verified emails from business websites with anti-blocking safeguards.
- Stores everything in a centralized Google Sheets CRM.
- Sends personalized emails via SendGrid, with unique embedded IDs for tracking.
- Tracks delivery, opens, clicks, and bounces in real time through webhook events.
- Detects replies from Gmail, matches them to the right campaign stage, and updates the CRM.
- Uses AI classification to label replies (Interested, Not Interested, Miscellaneous).
- Routes qualified replies directly to your sales team or Slack/Telegram channel.
- Automates follow-up emails (5-day & 10-day intervals) for non-responders.
- Provides light analytics & reporting in Google Sheets for quick insights (with deeper logs available in SendGrid).
๐ก Why This Workflow
- All-in-One Solution: Instead of juggling multiple tools, this workflow handles lead gen, outreach, tracking, and CRM updates in one place.
- Smart Reply Handling: Never lose a lead โ every reply is tracked, classified, and routed intelligently.
- Scalable & Modular: Each workflow (lead gen, email sending, webhook, replies, routing, follow-ups) can run independently or as part of the full system.
- Time-Saving: Reduces manual lead collection, email follow-up, and CRM updating by 90%+.
- Client-Ready: Built with reliability in mind โ randomized delays, duplicate prevention, priority logic for status updates, and AI-powered classification.
๐ค Who Itโs For
This workflow is ideal for:
- Agencies running cold campaigns for clients.
- B2B Businesses looking to automate lead generation and follow-ups.
- Freelancers / Consultants who need a plug-and-play outreach system without expensive SaaS subscriptions.
- Sales Teams that want structured, real-time leads routed directly to their inbox or Slack.
- Startups who want a scalable, low-cost alternative to tools like Apollo, Firecrawl, Bright Data or Reply.io.
โ๏ธ How It Works
๐งฉ 1. Lead Generation Workflow
๐ฏ Purpose
Scrape fresh B2B leads from Google Maps, crawl their websites to extract verified email addresses, and upload structured, clean lead data into a Google Sheets CRM.
๐ How It Works
1. User Input via Form Trigger
- The workflow begins with a form asking for:
- Business keyword (e.g. "Dentist")
- Location (e.g. "Florida")
- Lead limit (e.g. 50)
2. Scrape Google Maps via Apify
- Calls the Apify Google Maps Scraper Actor
- Extracts structured business data like:
Business Name,Website,Phone,Category,Rating,Address.
3. Website Filtering & Normalization
- Filters out businesses with no website
- Cleans up URLs
4. Website Email Extraction
- Sends direct HTTP GET requests to the homepage of each business
- Parses the raw HTML for public-facing email addresses using regex
- Implements anti-blocking techniques:
- Random delays between requests
- Custom headers / User-Agent spoofing
- Graceful skip on failures
5. Final Filtering & Data Structuring
- Keeps only businesses with a valid email address
- Constructs lead objects with:
Business Name,Category,Email,Website,Phone,Rating,Location.
6. Upload to Google Sheets CRM
- Pushes leads to a connected Google Sheet that acts as the systemโs central CRM
- This CRM becomes the source for the email sending workflow
๐งฉ 2. Send an Email Workflow
๐ฏ Purpose
Automatically sends personalized emails to verified leads using rotating templates, embedded ID tracking, and campaign-stage tagging.
๐ How It Works
1. Pull Active Leads from CRM
- Retrieves fresh leads from the Google Sheet where
2. Select a Random Template
- Pulls from a template library stored in a separate Google Sheet
- Injects lead-specific variables into placeholders like:
[Business Name],[Category],[Location], etc.
3. Embed Unique Tracking ID
- Appends an embedded ID token to the email. This enables accurate reply source tracking across all email stages
4. Send Email via SendGrid
- Sends the message using SendGrid's transactional API
- Emails are tagged internally according to email type.
๐งฉ 3. Webhook Event Workflow
๐ฏ Purpose
Processes SendGrid webhook events (e.g., delivered, opened, clicked, bounced) and updates the CRM with prioritized delivery status and engagement tracking โ using clean classification and smart update logic.
๐ How It Works
1. Receive Events via Webhook Trigger
- Listens for real-time webhook events from SendGrid, including:
- delivered, bounce, deferred, processed, open, click, unsubscribe, spamreport, etc.
2. Classify Each Event Type
- A custom code node adds a route label:
- status: delivery-level events
- engagement: recipient interaction events
- others: uncategorized or unsupported
3. Switch-Based Routing
- Status Events:
- Applies priority logic
- If multiple status events are received for the same lead, only the highest-priority event is stored
- Updates corresponding CRM fields:
- Engagement Events:
- Detects interactions like:
- Opened, Clicked, Unsubscribed, Spam Reported
- Updates CRM fields:
- Opened, Clicked, Unsubscribed, Spam Reported, Engaged At
- Preserve first-time interaction records and avoiding regressions
- Detects interactions like:
- Others Branch:
- Logs or gracefully skips events not explicitly supported
4. CRM Synchronization
- Merges event data with the correct lead by matching Email
- Ensures all updates are timestamped and consistent across systems
๐งฉ 4. Reply Update Database Workflow
๐ฏ Purpose
Polls Gmail inbox, extracts replies, determines their source, and logs them in both the CRM and a message tracker sheet.
๐ How It Works
1. Poll Gmail for New Replies
- Uses Gmail API to fetch recent messages
- Filters out auto-replies, no-reply addresses, or irrelevant responses
2. Prevent Duplicate Processing
- Checks each message against a "Processed Message IDs" Google Sheet
- Skips if the message has been handled before
3. Extract Reply Metadata 4. Match to Lead & Update CRM
- Determines the original email stage based on ID
- Updates necessary fields
๐งฉ 5. Email Routing Workflow
๐ฏ Purpose
Uses AI to classify replies by intent (Interested, Not Interested, or Miscellaneous) and automatically routes, labels, and logs them accordingly.
๐ How It Works
1. Receive Cleaned Reply
- Triggered after a set time interval
2. Classify Using AI (LangChain / OpenAI)
- The reply is analyzed and categorized as:
- Interested: wants to talk, asks for more info
- Not Interested: says no or unsubscribes
- Miscellaneous: unclear or unrelated response
3. Gmail Label Assignment
- Adds Gmail label based on classification
4. Handle โInterestedโ Replies
- If Interested:
- Adds label in Gmail
- Forwards message to a sales or response channel
- Updates Google Sheet CRM
๐งฉ 6. Follow-Up Email Workflow
๐ฏ Purpose
Automatically sends up to two follow-up emails to leads who showed interest (opened or clicked) but havenโt replied yet.
๐ How It Works
1. Scheduled Execution
- Runs daily or at set intervals
2. Filter Leads for Follow-Up
- Checks that desired conditions are met:
- Required number of days have passed:
- 5 days โ Follow-Up 1
- 10 days โ Follow-Up 2
- Required number of days have passed:
3. Choose and Personalize Template
- Injects lead-specific data
- Embeds corresponding for reply tracking
4. Send via SendGrid
- Message is tagged by stage
- Sent using the same logic as the original email
5. Update CRM
- Increments:
- Follow-Up Sent flag
- Follow-Up Count
- Follow-Up Time field
โ Setup Requirements (Before You Start)
Prepare these items to avoid interruptions during setup:
- ๐ Domain DNS Access
- Youโll need to add TXT/CNAME records in your registrar (GoDaddy, Namecheap, Cloudflare, etc.) to authenticate your domain with SendGrid.
- ๐ง Domain Email Address or Single Sender Authentication (e.g., hello@yourbusiness.com)
- Needed for SendGrid domain authentication (donโt use Gmail/Yahoo).
- This step ensures emails are not flagged as spam. Tip: If you donโt own a domain, you can use a single sender email to test, but for production you MUST authenticate a domain.
- ๐ API Keys / Credentials
- Apify API Key โ for Google Maps scraping.
- SendGrid API Key โ for sending emails + webhook events.
- Google Sheets OAuth Credentials โ for CRM integration.
- Gmail API Credentials โ for reply detection.
- OpenAI API Key โ for AI-based reply classification.
- ๐ Google Sheet (CRM)
- Add desired columns: Business Name, Email, Website, Phone, Category, Status, Reply, Follow-Up Count.
- ๐ n8n Environment (Cloud or Self-Hosted)
- Must allow Apify node installation.
๐ How to Set It Up
- Open n8n (Cloud or Self-Hosted).
- Install Apify node before importing.
- Search Apify โ click Install.
- Import the provided .json workflow file into your n8n editor.
- Set up the required credentials:
- ๐ Apify API Key,
- ๐ SendGrid API Key,
- ๐ Google Sheets OAuth,
- ๐ Gmail API,
- ๐ OpenAI API Key.
- Prepare your Google Sheet (CRM).
- Verify column names match your workflow fields.
- Adjust โGet Desired Fieldsโ node in n8n โLead generation workflowโ if you add/remove columns.
- Enable SendGrid Webhook Events.
- Go to SendGrid โ Settings โ Mail Settings โ Event Webhook.
- Paste the webhook URL from your n8n โWebhook Event Workflowโ.
- Select: Delivered, Opened, Clicked, Bounced, Unsubscribed, Spam Report.
- Run a test.
- Trigger the Lead Generation workflow โ check Google Sheets for leads.
- Send a test email โ verify delivery + engagement updates in CRM.
- Reply from a test inbox โ confirm Gmail polling + AI classification.
๐ Additional Provided Resources.
To help you get started faster, youโll also receive:
- SendGrid Setup and Troubleshooting document.
- Two ready-to-use Google Sheets example templates which can be modified to suit your business needs:
- Email Workflow DB CRM
- Includes:
- Leads Tab โ structured space for scraped businesses and contact details.
- Email Templates Tab โ pre-written templates for the main email, 1st follow-up, and 2nd follow-up (with placeholders for personalization).
- Analytics Tab โ light reporting on sends, opens, clicks, and replies to give quick campaign insights.
- Includes:
- Processed Gmails IDs
- A simpler sheet designed for Gmail reply handling.
- Useful for tracking processed messages and avoiding duplicates while you familiarize yourself with how reply updates work.
- Email Workflow DB CRM
๐จ Customization Tips
- Templates: Update the Google Sheets Templates tab with your own outreach copy. Use placeholders like
[Business Name],[Location],[Category]so each email feels personalized. - CRM Fields: Add or remove CRM columns depending on your business needs (e.g., Industry, Revenue, Sales Owner, Notes). Just make sure the field names match in n8nโs โGrab Desired Fieldsโ nodes in the Lead generation workflow.
- Follow-Up Logic: Adjust the timing for follow-ups. Default is 5 days (Follow-Up 1) and 10 days (Follow-Up 2), but you can easily change this to 3/7/14 days or any schedule your sales process requires.
- Reply Routing: Customize how AI classification works. For example, rename labels (โHot Leadโ, โNot Interestedโ, โOut of Scopeโ) and route replies differently (e.g., forward โInterestedโ to your sales inbox, Slack channel, or Telegram bot).
- Analytics & Reporting: Expand the Google Sheets reporting tab. You can add pivot tables for deeper campaign insights. For more advanced analytics, SendGrid also keeps full logs.
- Scalability:
- Add proxy handling for higher-volume scraping.
- Switch to a database (Postgres, Supabase, MongoDB) instead of Google Sheets if managing thousands of leads.
- Use multiple SendGrid accounts or IP warm-up strategies for large-scale sending.
- Scraping Alternatives:
- If you prefer not to use direct HTTP requests for email extraction, you can integrate with external scrapers like:
- Firecrawl โ lightweight scraper for web/email extraction.
- Bright Data โ residential proxies + scraping tools.
- Apify Website Scrapers โ customizable actors for deep site scraping.
- These can plug into the workflow instead of (or alongside) the built-in email scraper.
- If you prefer not to use direct HTTP requests for email extraction, you can integrate with external scrapers like:
โจ Predefined Templates vs. AI-Generated Emails
By default, this workflow uses predefined templates stored in Google Sheets. This design choice was intentional, and hereโs why:
- โ Reliability: Alway work, no prompt issues.
- โ Cost Savings: no API token usage.
- โ Total Control, Consistent & Customizable: You control tone and can tweak anytime.
โก That said, you can absolutely swap out the template system for AI-based generation if you prefer dynamic messaging. The workflow is flexible โ just keep in mind the trade-offs in cost, reliability, and control. โก Best approach: start with templates for stability, then add AI if you want more variety.
Automate B2B Lead Generation & Email Campaigns with Google Maps, SendGrid & AI
This n8n workflow automates the process of generating B2B leads, enriching their data using Google Maps, classifying them with AI, and initiating targeted email campaigns. It streamlines lead management from initial data collection to personalized outreach.
What it does
This workflow performs the following key steps:
- Triggers: The workflow can be initiated either manually or via a webhook (e.g., from a form submission).
- Collects Lead Data: Reads lead information from a Google Sheet.
- Loops Over Leads: Processes each lead individually.
- Enriches Data with Google Maps: For each lead, it performs an HTTP request to Google Maps to find business details based on a search query (e.g., "company name + city").
- Filters Valid Leads: Checks if a Google Maps result was found for the lead.
- Extracts & Sets Company Information: If a valid Google Maps result exists, it extracts and sets relevant company details (e.g., address, website, phone).
- Classifies Leads with AI: Uses an OpenAI Chat Model and a Text Classifier to categorize the lead based on extracted information, likely for targeting purposes.
- Splits Leads by Classification: Routes leads based on their AI classification.
- Sends Personalized Emails:
- For "Cold Leads," it sends a personalized email via SendGrid.
- For "Warm Leads," it sends a different personalized email via Gmail.
- Logs Activity: Records the outcome of the email sending process (e.g., email sent successfully, no email sent).
- Updates Google Sheets: Merges the processed data and updates the original Google Sheet with the enriched information and campaign status.
Prerequisites/Requirements
To use this workflow, you will need:
- n8n Instance: A running n8n instance.
- Google Sheets Account: To store and manage your lead data.
- Google Cloud Project & API Key: With access to Google Maps Platform APIs (specifically Geocoding and Place Search, depending on the exact HTTP Request configuration).
- OpenAI API Key: For the AI Chat Model and Text Classifier nodes.
- SendGrid Account: For sending cold outreach emails.
- Gmail Account: For sending warm outreach emails.
- Webhook (Optional): If you intend to trigger the workflow via an external system.
Setup/Usage
- Import the Workflow: Download the provided JSON and import it into your n8n instance.
- Configure Credentials:
- Set up your Google Sheets credential.
- Set up your Google OAuth credential (for Google Maps HTTP Request).
- Set up your OpenAI credential.
- Set up your SendGrid credential.
- Set up your Gmail credential.
- Update Google Sheets Node (ID: 18):
- Specify the Spreadsheet ID and Sheet Name where your lead data is stored.
- Ensure the column headers in your sheet match the data expected by the workflow (e.g., "Company Name", "City").
- Configure HTTP Request Node (ID: 19):
- Review the Google Maps API endpoint and parameters. Ensure your Google Maps API key is correctly configured and enabled for the necessary services.
- Adjust the search query to accurately find business information (e.g., combining company name and city from your Google Sheet).
- Review AI Nodes (ID: 1153, 1265):
- OpenAI Chat Model: Ensure the model and prompt are configured for your specific lead classification needs.
- Text Classifier: Adjust the categories and examples to accurately classify your leads (e.g., "Cold Lead", "Warm Lead", "Unqualified").
- Configure Email Nodes (ID: 356, 439):
- SendGrid (ID: 439): Customize the email subject, body, sender, and recipient mapping for cold leads.
- Gmail (ID: 356): Customize the email subject, body, sender, and recipient mapping for warm leads.
- Adjust Logic (ID: 20, 112, 844):
- If (ID: 20): Review the condition for checking if Google Maps data was found.
- Switch (ID: 112): Ensure the cases for "Cold Lead" and "Warm Lead" (or your custom classifications) accurately route the items.
- Filter (ID: 844): Adjust any filtering conditions as needed for lead qualification.
- Activate the Workflow: Once all configurations are complete, activate the workflow. You can trigger it manually for testing or set up the webhook to receive external data.
Related Templates
AI-powered code review with linting, red-marked corrections in Google Sheets & Slack
Advanced Code Review Automation (AI + Lint + Slack) Whoโs it for For software engineers, QA teams, and tech leads who want to automate intelligent code reviews with both AI-driven suggestions and rule-based linting โ all managed in Google Sheets with instant Slack summaries. How it works This workflow performs a two-layer review system: Lint Check: Runs a lightweight static analysis to find common issues (e.g., use of var, console.log, unbalanced braces). AI Review: Sends valid code to Gemini AI, which provides human-like review feedback with severity classification (Critical, Major, Minor) and visual highlights (red/orange tags). Formatter: Combines lint and AI results, calculating an overall score (0โ10). Aggregator: Summarizes results for quick comparison. Google Sheets Writer: Appends results to your review log. Slack Notification: Posts a concise summary (e.g., number of issues and average score) to your teamโs channel. How to set up Connect Google Sheets and Slack credentials in n8n. Replace placeholders (<YOURSPREADSHEETID>, <YOURSHEETGIDORNAME>, <YOURSLACKCHANNEL_ID>). Adjust the AI review prompt or lint rules as needed. Activate the workflow โ reviews will start automatically whenever new code is added to the sheet. Requirements Google Sheets and Slack integrations enabled A configured AI node (Gemini, OpenAI, or compatible) Proper permissions to write to your target Google Sheet How to customize Add more linting rules (naming conventions, spacing, forbidden APIs) Extend the AI prompt for project-specific guidelines Customize the Slack message formatting Export analytics to a dashboard (e.g., Notion or Data Studio) Why itโs valuable This workflow brings realistic, team-oriented AI-assisted code review to n8n โ combining the speed of automated linting with the nuance of human-style feedback. It saves time, improves code quality, and keeps your teamโs review history transparent and centralized.
Dynamic Hubspot lead routing with GPT-4 and Airtable sales team distribution
AI Agent for Dynamic Lead Distribution (HubSpot + Airtable) ๐ง AI-Powered Lead Routing and Sales Team Distribution This intelligent n8n workflow automates end-to-end lead qualification and allocation by integrating HubSpot, Airtable, OpenAI, Gmail, and Slack. The system ensures that every new lead is instantly analyzed, scored, and routed to the best-fit sales representative โ all powered by AI logic, sir. --- ๐ก Key Advantages โก Real-Time Lead Routing Automatically assigns new leads from HubSpot to the most relevant sales rep based on region, capacity, and expertise. ๐ง AI Qualification Engine An OpenAI-powered Agent evaluates the leadโs industry, region, and needs to generate a persona summary and routing rationale. ๐ Centralized Tracking in Airtable Every lead is logged and updated in Airtable with AI insights, rep details, and allocation status for full transparency. ๐ฌ Instant Notifications Slack and Gmail integrations alert the assigned rep immediately with full lead details and AI-generated notes. ๐ Seamless CRM Sync Updates the original HubSpot record with lead persona, routing info, and timeline notes for audit-ready history, sir. --- โ๏ธ How It Works HubSpot Trigger โ Captures a new lead as soon as itโs created in HubSpot. Fetch Contact Data โ Retrieves all relevant fields like name, company, and industry. Clean & Format Data โ A Code node standardizes and structures the data for consistency. Airtable Record Creation โ Logs the lead data into the โLeadsโ table for centralized tracking. AI Agent Qualification โ The AI analyzes the lead using the TeamDatabase (Airtable) to find the ideal rep. Record Update โ Updates the same Airtable record with the assigned team and AI persona summary. Slack Notification โ Sends a real-time message tagging the rep with lead info. Gmail Notification โ Sends a personalized handoff email with context and follow-up actions. HubSpot Sync โ Updates the original contact in HubSpot with the assignment details and AI rationale, sir. --- ๐ ๏ธ Setup Steps Trigger Node: HubSpot โ Detect new leads. HubSpot Node: Retrieve complete lead details. Code Node: Clean and normalize data. Airtable Node: Log lead info in the โLeadsโ table. AI Agent Node: Process lead and match with sales team. Slack Node: Notify the designated representative. Gmail Node: Email the rep with details. HubSpot Node: Update CRM with AI summary and allocation status, sir. --- ๐ Credentials Required HubSpot OAuth2 API โ To fetch and update leads. Airtable Personal Access Token โ To store and update lead data. OpenAI API โ To power the AI qualification and matching logic. Slack OAuth2 โ For sending team notifications. Gmail OAuth2 โ For automatic email alerts to assigned reps, sir. --- ๐ค Ideal For Sales Operations and RevOps teams managing multiple regions B2B SaaS and enterprise teams handling large lead volumes Marketing teams requiring AI-driven, bias-free lead assignment Organizations optimizing CRM efficiency with automation, sir --- ๐ฌ Bonus Tip You can easily extend this workflow by adding lead scoring logic, language translation for follow-ups, or Salesforce integration. The entire system is modular โ perfect for scaling across global sales teams, sir.
Track daily moods with AI analysis & reports using GPT-4o, Data Tables & Gmail
Track your daily mood in one tap and receive automated AI summaries of your emotional trends every week and month. Perfect for self-reflection, wellness tracking, or personal analytics. This workflow logs moods sent through a webhook (/mood) into Data Tables, analyzes them weekly and monthly with OpenAI (GPT-4o), and emails you clear summaries and actionable recommendations via Gmail. โ๏ธ How It Works Webhook โ Mood โ Collects new entries (๐, ๐, or ๐ฉ) plus an optional note. Set Mood Data โ Adds date, hour, and note fields automatically. Insert Mood Row โ Stores each record in a Data Table. Weekly Schedule (Sunday 20:00) โ Aggregates the last 7 days and sends a summarized report. Monthly Schedule (Day 1 at 08:00) โ Aggregates the last 30 days for a deeper AI analysis. OpenAI Analysis โ Generates insights, patterns, and 3 actionable recommendations. Gmail โ Sends the full report (chart + AI text) to your inbox. ๐ Example Auto-Email Weekly Mood Summary (last 7 days) ๐ 5 โโโโโโโโโโ ๐ 2 โโโโ ๐ฉ 0 Average: 1.7 (Positive ๐) AI Insights: Youโre trending upward this week โ notes show that exercise days improved mood. Try keeping short walks mid-week to stabilize energy. ๐งฉ Requirements n8n Data Tables enabled OpenAI credential (GPT-4o or GPT-4 Turbo) Gmail OAuth2 credential to send summaries ๐ง Setup Instructions Connect your credentials: Add your own OpenAI and Gmail OAuth2 credentials. Set your Data Table ID: Open the Insert Mood Row node and enter your own Data Table ID. Without this, new moods wonโt be stored. Replace the email placeholder: In the Gmail nodes, replace your.email@example.com with your actual address. Deploy and run: Send a test POST request to /mood (e.g. { "mood": "๐", "note": "productive day" }) to log your first entry. โ ๏ธ Before activating the workflow, ensure you have configured the Data Table ID in the โInsert Mood Rowโ node. ๐ง AI Analysis Interprets mood patterns using GPT-4o. Highlights trends, potential triggers, and suggests 3 specific actions. Runs automatically every week and month. ๐ Security No personal data is exposed outside your n8n instance. Always remove or anonymize credential references before sharing publicly. ๐ก Ideal For Personal mood journaling and AI feedback Therapists tracking client progress Productivity or self-quantification projects ๐๏ธ Sticky Notes Guide ๐ก Mood Logging Webhook POST /mood receives mood + optional note. โ ๏ธ Configure your own Data Table ID in the โInsert Mood Rowโ node before running. ๐ข Weekly Summary Runs every Sunday 20:00 โ aggregates last 7 days โ generates AI insights + emails report. ๐ต Monthly Summary Runs on Day 1 at 08:00 โ aggregates last 30 days โ creates monthly reflection. ๐ฃ AI Analysis Uses OpenAI GPT-4o to interpret trends and recommend actions. ๐ Email Delivery Sends formatted summaries to your inbox automatically.