BULDRR AI Vikash KumarSchedule a Call
Updated Workflow #1117

Automate Lead Handling & Emailing with n8n AI Agent

This n8n workflow automates lead processing by analyzing customer inquiries, filtering valid leads, and generating targeted email notifications. Using AI to pinpoint correct contacts, it streamlines communication and reduces manual errors for businesses managing incoming website leads.

Automate Lead Handling & Emailing with n8n AI Agent
CONNECTS
agent, lmChatOpenAi, googleSheetsTool, set, if, microsoftOutlook, code, googleDocsTool, httpRequest, webhook, stickyNote
Learn it with AI
✦ SEE IT BEFORE YOU DOWNLOAD

The canvas, and the 11 nodes behind it.

Preview of the Automate Lead Handling & Emailing with n8n AI Agent workflow canvas in n8n
✦ NODE BY NODE

What runs inside this workflow

Automate Lead Handling & Emailing with n8n AI Agent is built from these n8n nodes: agent, lmChatOpenAi, googleSheetsTool, set, if, microsoftOutlook, code, googleDocsTool, httpRequest, webhook, stickyNote.

    ✦ LEARN HOW TO BUILD THIS WORKFLOW WITH AI
    Send this workflow to your assistant and have it taught to you.

    Each button opens the assistant with the prompt already written — asking it to explain this exact workflow step by step, as if teaching a complete beginner.

    Using our workflows often?
    Mark BULDRR AI as a preferred source and our templates surface higher in your own Google results.
    Add as a preferred source

    What This Workflow Does ⚙️

    This workflow connects ERPNext leads to company contacts and sends notification emails automatically.
    It stops the need to check every lead manually.
    The workflow reads new leads, finds the right person, and writes an email to tell them about the customer inquiry.
    You get faster replies and fewer lost chances to sell.


    The workflow starts when a lead is made in ERPNext.
    It gathers lead details, reads notes to understand what the customer wants, and looks up product and contact info in Google Docs and Sheets.
    Then, an AI node creates a clear, polite email summary.
    Finally, the workflow sends the email through Microsoft Outlook.



    Tools and Services Used

    • ERPNext: Provides lead data and triggers for new leads.

    • n8n: Automates the entire process with nodes including webhook, HTTP Request, and AI Agent.

    • AI Agent node (LangChain with OpenAI): Reads notes, extracts details, classifies inquiry, drafts email.

    • Google Docs: Stores company profile and policy text for referencing.

    • Google Sheets: Holds contact database to map inquiries to the right team.

    • Microsoft Outlook: Sends the finalized email notifications.

    • OpenAI API: Enables AI processing inside n8n.


    Inputs, Processing Steps, and Outputs

    Inputs

    • New lead data from ERPNext webhook.

    • Company documents from Google Docs.

    • Contact database from Google Sheets.

    Processing Steps

    1. Webhook catches new lead creation with HTTP POST.

    2. Checks lead source is "Website" and status is "Open" with the If node.

    3. Fetches full lead details via HTTP Request to ERPNext API.

    4. Verifies lead has notes to process.

    5. Loads company profile and policies from Google Docs, and contacts from Google Sheets.

    6. The AI Agent node reads lead notes and documents, then extracts needed data like customer name, inquiry type, and who to contact.

    7. Checks AI result to confirm the inquiry is valid.

    8. A Code node extracts email addresses, subject line, and email text from the AI output.

    9. Another Code node formats the email body text into clean HTML.

    10. Sends the email to chosen contacts using the Microsoft Outlook node.

    Outputs

    • Professional, well-structured email notifications sent automatically.

    • Faster response to customer inquiries.

    • Reduced manual work and human errors in lead handling.


    Beginner Step-by-Step: How to Use This Workflow in n8n

    Step 1: Import the Workflow

    1. Download the workflow file from this page using the Download button.

    2. Open the n8n editor.

    3. Click "Import from File" and select the downloaded workflow file.

    Step 2: Configure Credentials and Settings

    1. Add API credentials for ERPNext, Google Docs, Google Sheets, Microsoft Outlook, and OpenAI within n8n.

    2. Update any IDs such as Google Sheet IDs, Google Doc URLs, or email addresses if needed.

    3. Check the Webhook node URL and set it in ERPNext webhook settings.

    4. If prompts or code blocks require changes, copy and paste the exact code provided in the workflow description.

    Step 3: Test the Workflow

    1. Trigger a test lead in ERPNext to send data to the webhook.

    2. Monitor n8n runs to confirm data flows correctly and emails are generated.

    Step 4: Activate the Workflow

    1. Switch the workflow status to Active.

    2. Now all new leads from ERPNext will be processed automatically.

    You can expand or customize later, but this gets the automation running fast and reduces manual work.
    For advanced privacy or full control, consider self-host n8n.



    Customization Ideas ✏️

    • Change the If node filters to include leads from email or phone.

    • Add a WhatsApp step after sending emails for quick alerts.

    • Edit the AI Agent prompt to email multiple contacts at once.

    • Include links or attachments fetched from ERPNext lead files.

    • Modify email wording or branding inside the AI prompt in the Customer Lead AI Agent node.


    Troubleshooting

    • Invalid lead error: check lead notes and AI prompt completeness.

    • Emails not sending: renew Microsoft Outlook OAuth credentials.

    • Google Sheets contact list not loading: verify sheet ID and share settings.


    Pre-Production Checklist ✅

    • Make sure ERPNext triggers webhook with new lead data.

    • Test AI Agent node with different lead notes.

    • Confirm Google Docs and Sheets nodes access and permissions.

    • Send test email through Microsoft Outlook node.

    • Confirm that invalid leads are blocked and no emails sent.


    Summary of Benefits and Outcomes

    ✓ Saves over 10 hours weekly by automating lead reviews.
    ✓ Delivers fast, accurate customer inquiry emails.
    ✓ Cuts human error and lost sales chances.
    ✓ Uses AI plus real company data for precise routing.
    ✓ Easy to import and activate inside the n8n editor.
    ✓ Scales with company needs and communication channels.



    Code Snippet: Extract Fields From AI Output

    This JavaScript Code node parses the AI generated text to extract emails, subject, and email body.


    const textOutput = $json?.output || '';
    function extractFields(text) {
     const fields = {};
     const emailMatch = text.match(/\*\*Email Address\(es\):\*\*\s*([^\n]+)/);
     const subjectMatch = text.match(/_Subject:\s*([^_]+)/);
     const emailBodyMatch = text.match(/Dear[\s\S]+/);
     fields.email_addresses = emailMatch ? emailMatch[1].trim() : null;
     fields.subject = subjectMatch ? subjectMatch[1].trim() : null;
     fields.email_body = emailBodyMatch ? emailBodyMatch[0].trim() : null;
     return fields;
    }
    const extractedFields = extractFields(textOutput);
    return { json: extractedFields };

    Code Snippet: Format Email Body to HTML

    This Code node converts plain text email content into a nice HTML structure for professional emails.


    const emailBody = $json.email_body || '';
    function formatEmailBodyAsHtml(body) {
     let htmlBody = body
     .replace(/\*\*Customer Name:\*\* (.+)/, '<p><strong>Customer Name:</strong> $1</p>')
     .replace(/\*\*Organization:\*\* (.+)/, '<p><strong>Organization:</strong> $1</p>')
     .replace(/\*\*Contact Information:\*\* (.+)/, '<p><strong>Contact Information:</strong> $1</p>')
     .replace(/\*\*Inquiry Summary:\*\*\s*([\s\S]+?)(?=\n\n\*\*Action Required:)/, '<p><strong>Inquiry Summary:</strong> $1</p>')
     .replace(/\*\*Action Required:\*\*\s*([\s\S]+)/, '<p><strong>Action Required:</strong> $1</p>');
     htmlBody = htmlBody
     .replace(/Dear (.+?),/, '<p>Dear <strong>$1</strong>,</p>')
     .replace(/Thank you,\s+(.+)/, '<p>Thank you,<br><strong>$1</strong></p>');
     return htmlBody;
    }
    const formattedHtmlBody = formatEmailBodyAsHtml(emailBody);
    return { html: formattedHtmlBody };

    Frequently Asked Questions

    How does the <a href="https://buldrr.com/workflows/automate-lead-scoring-slack-alerts-n8n-madkudu-hunter/" title="Automate Lead Scoring and Slack Alerts with n8n, MadKudu &#038; Hunter" data-wpil-monitor-id="661">n8n workflow get new lead</a> details from ERPNext?

    The workflow uses a webhook node that receives new lead data when ERPNext creates a lead. It then fetches full lead details using an <a href="https://buldrr.com/a-practical-guide-to-learning-n8n/" title="A Practical Guide to Learning n8n" data-wpil-monitor-id="659">HTTP Request node</a> calling the ERPNext API.

    What role does the AI Agent node play in this lead handling workflow?

    The AI Agent node reads incoming lead notes and company documents, extracts key inquiry details, classifies the inquiry, finds responsible contacts, and drafts the notification email text.

    How can the <a href="https://buldrr.com/workflows/automate-ai-powered-user-interviews-n8n-redis/" title="Automate AI-Powered User Interviews with n8n &#038; Redis" data-wpil-monitor-id="662">user test the imported workflow in n8n</a> before activating it?

    After importing, the user configures credentials and IDs, triggers a test lead in ERPNext, then monitors n8n to confirm correct data processing and email sending before activating the workflow.

    What should be checked if emails do not send from the Microsoft Outlook node?

    Check that <a href="https://buldrr.com/workflows/automate-google-calendar-to-outlook-event-sync-n8n/" title="Automate Google Calendar to Outlook Event Sync with n8n" data-wpil-monitor-id="660">Microsoft Outlook OAuth credentials in n8n</a> are valid and not expired. Also verify correct field mappings for recipient emails and subject lines.

    Vikash Kumar
    WRITTEN BY
    Vikash Kumar
    Founder, BULDRR AI
    Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.

    Related workflows.

    All 10,467+ templates →
    FREE Automate Twist Channel Creation and Messaging with n8n This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications. Open template → FREE Automate IT Support with Slack and OpenAI in n8n Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time. Open template → FREE Automate Crypto Analysis with CoinMarketCap & n8n AI Agent Discover how this unique n8n workflow leverages CoinMarketCap's multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration. Open template → FREE Generate On-Brand Blog Articles Using n8n and OpenAI This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time. Open template → FREE Automate Archiving Spotify Discover Weekly with n8n This automation workflow solves the hassle of manually archiving your Spotify Discover Weekly playlist by automatically comparing and adding only unique tracks to an archive playlist every Monday. It saves time, avoids duplicates, and keeps your archived music collection organized effortlessly using n8n. Open template → FREE Automate Analyzing Sales Call Transcripts with n8n & AI Agents This n8n workflow automates the extraction of structured insights from sales call transcripts using AI agents focused on sales, marketing, and product teams. It streamlines data processing, enabling faster decision-making and team alignment. Open template → FREE Automated SSL Expiry Alert System with n8n & Google Sheets This n8n workflow automates SSL certificate expiry monitoring by fetching URLs from Google Sheets, checking their SSL status via SSL-Checker.io, updating the sheet with results, and sending targeted email and Telegram alerts for certificates that are invalid or near expiry. Open template → FREE Automate Task Creation in ClickUp with n8n Struggling to manually create tasks in ClickUp? This beginner-friendly n8n workflow automates task creation, saving you time and reducing errors. Learn how to create tasks automatically with a simple trigger and ClickUp integration. Open template → FREE Automate Todoist Task Snoozing with n8n Workflow Struggling to manage and snooze your Todoist tasks efficiently? This detailed n8n workflow automates moving tasks between Inbox and Snoozed projects based on due dates, saving you hours of manual task juggling and ensuring timely task returns. Open template → FREE Build OpenAI Assistant with Google Drive Using n8n Automation This workflow automates creating and updating an OpenAI-powered Travel Assistant using a Google Drive file for accurate, specific user replies. It saves time by streamlining assistant updates and chat interactions seamlessly. Open template → FREE Automate WooCommerce Product Announcements on Twitter & Telegram Save time and boost your WooCommerce store's visibility by automatically posting new product announcements on Twitter and Telegram with this n8n workflow. Avoid manual posting errors and reach your audience instantly when new products go live. Open template → FREE Automate Zendesk to Asana Task Creation with n8n This detailed guide shows how to automate task creation in Asana from new Zendesk tickets using n8n. It solves the common challenge of manually duplicating support requests into project management, saving time and reducing errors. Open template → FREE Automate Image Alt Text Auditing & Enhancement with n8n & OpenAI Discover how this n8n workflow automates auditing and enhancing image alt text from any webpage using OpenAI GPT-4. It helps fix poor or missing alt attributes quickly and accurately, saving hours of manual work and improving web accessibility. Open template → FREE Create OpenAI Citation Workflow in n8n for File Retrieval This n8n workflow automates citation and source retrieval from OpenAI's vector store files, ensuring accurate content referencing and formatted output. It solves the problem of incomplete or strange citation text generated by AI, providing reliable markdown or HTML-ready citations for file-based AI assistance. Open template → FREE Automate Squarespace Order Fulfillment with n8n Workflow This n8n workflow automates order fulfillment for Squarespace Commerce by fetching pending orders and fulfilling them automatically, saving hours of manual work. It ensures timely fulfillment and customer notifications with seamless API integration. Open template → FREE Phishing Analysis Automation with n8n, URLScan.io & VirusTotal Automate phishing URL analysis with n8n using URLScan.io and VirusTotal. This workflow extracts URLs from unread Outlook emails, scans for threats, and reports via Slack, saving hours on threat detection. Open template → FREE Automate Image Analysis with Local Ollama Vision Models in n8n Struggling to extract detailed insights from images for business or research? This n8n workflow automates exhaustive image analysis using multiple local Ollama Vision Models, delivering structured, markdown-formatted results saved directly to Google Docs for collaboration and ease of use. Open template → FREE Automate Website Change Alerts N8N Telegram — Complete Guide [2026] Learn how to automate website change alerts n8n telegram with this step-by-step guide. Includes workflow examples, tips, and best practices for 2026. Open template → FREE Automate Text-to-Speech with Elevenlabs & n8n Webhook Save hours in your content creation by automating text-to-speech generation using n8n's webhook and Elevenlabs API. This workflow ensures seamless audio generation from text inputs, eliminating manual conversion errors and delays. Open template → FREE Automate Jira Notifications to Telegram with n8n Workflow This detailed guide shows how to automate Jira issue notifications to Telegram using n8n. Save hours by instantly sending updates, creation alerts, and assignment notifications to the right Telegram users, improving team communication and tracking. Open template → FREE Automate Daily Berlin Weather Updates to LINE with n8n Save time and stay informed by automatically sending daily weather updates for Berlin via LINE using n8n automation. This workflow fetches weather data every morning and messages you directly, eliminating manual checking and keeping you updated efficiently. Open template → FREE n8n Twitter Thread Generator 2026: AI Writes & Posts Threads From Any Content This n8n workflow uses AI to automatically convert any content — blog posts, videos, articles — into ready-to-post Twitter/X threads, complete with hooks and formatting. Open template → FREE Backup n8n Workflows to Bitbucket with Rate Limit Handling Automate daily backups of your n8n workflows directly to Bitbucket, intelligently managing API rate limits to avoid errors. This workflow ensures your automation definitions are safely versioned with minimal manual effort. Open template → FREE Automate Member and Activity Sync from Google Sheets to Orbit This blog explains how to automate moving community member data and their activities from Google Sheets into Orbit using n8n, solving tedious manual updates and ensuring accurate data syncing. Open template → FREE Sync Outlook Calendar with Notion via n8n Automation This workflow automates syncing Microsoft Outlook Calendar events into a Notion database. It solves the problem of manual calendar updates, saving time and reducing errors by automatically creating or updating Notion pages for your events. Open template →
    ✦ WANT THIS RUNNING IN YOUR BUSINESS?

    We’ll set it up for you.

    Tell us what you want it to do. We’ll wire the workflow, connect the credentials, and hand it over running.

    Keep exploring.