n8n

How to Automate ERPNext Outlook Lead Routing?

Capture new website leads from ERPNext and send the right email from Outlook in minutes. An AI agent reads the lead note and your company info to decide if the inquiry is valid and who should respond. Great for sales teams with many products and owners.

Here is how it runs: A webhook fires when a Lead is created in ERPNext. Filters pass only open leads from the Website source and then fetch full details including notes. The AI agent uses OpenAI plus your Google Docs company profile and policies, the abbreviations sheet, and a contacts sheet to classify the request, pick recipients, and write a clear email body. If the agent marks the inquiry invalid, the flow stops. If valid, code extracts the subject and recipient emails, converts the message to HTML, adds an ERPNext lead link, and sends from Microsoft Outlook.

Setup needs document IDs for the two Google Docs and the Google Sheets files, and working ERPNext API and Outlook OAuth credentials. Teams typically cut triage time by about 80 percent and can handle more web traffic without extra staff. Use it to route product specific questions, auto reply to valid leads, and keep a clean audit trail in ERPNext.

What are the key features?

  • Webhook listens to new ERPNext leads and starts the flow
  • Filters allow only open leads from the Website source to continue
  • Retrieves full lead details and notes from ERPNext before AI review
  • AI agent uses OpenAI plus Google Docs and Google Sheets as context
  • Validates inquiries and drops spam or unrelated requests
  • Parses AI output to extract subject and recipient email addresses
  • Converts the email body to clean HTML for a professional look
  • Sends the message through Microsoft Outlook with an ERPNext lead link
  • Uses an abbreviations sheet to normalize terms in the inquiry
  • Routes emails to the right owner based on the contacts database

What are the benefits?

  • Reduce manual lead triage from 1 hour to 5 minutes per lead
  • Streamline routing by about 80 percent with AI validation
  • Improve recipient accuracy by using your contacts sheet and policies
  • Connect five systems seamlessly to avoid switching between apps
  • Handle up to 10 times more inbound leads without extra staff

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with ERPNext, OpenAI, Google Docs, Google Sheets and Microsoft Outlook. See the Tools Required section above for links to create accounts with these services.
  3. In ERPNext, create a webhook on Doctype Lead with trigger on_insert and paste the n8n Webhook node URL. Include doc.name, source, status, and notes in the payload.
  4. Open the Webhook node in n8n and copy the production URL back into ERPNext once you are ready to go live.
  5. Configure ERPNext credentials: Double click the Get Lead Data from ERPNext node, choose 'Create new credential', select ERPNext API, enter your ERPNext base URL, API Key, and API Secret, then test the connection.
  6. Set Google Docs context: Open the Company Profile and Company Policies nodes and replace the placeholder document IDs with your actual Google Docs IDs. Ensure these docs are accessible to the connected Google account.
  7. Set Google Sheets data: Open the Abbreviations and Company Contact Database nodes, paste the correct spreadsheet IDs, and select the right sheet tab. The contacts sheet should map products or services to owners and email addresses.
  8. Add OpenAI: Double click the OpenAI Chat Model node, create a new OpenAI API Key credential, paste your key from the OpenAI dashboard, and select a suitable chat model.
  9. Tune the AI agent: Open the Customer Lead AI Agent node. Ensure the prompt asks the model to output clear fields like Subject, Email Addresses, and Email Body so the parsing code can read them.
  10. Connect Outlook: Double click the Microsoft Outlook node, create a new Microsoft Outlook OAuth2 credential, sign in with the mailbox that will send emails, and confirm the connection.
  11. Review filters: Open the If node labeled Source Website and Status Open and match the exact field names from your ERPNext payload. Adjust if your labels differ. Keep the Inquiry has Notes check if you only want leads with notes.
  12. Run a test: Create a new Lead in ERPNext with source Website, status Open, and a clear note. Watch the execution in n8n. Confirm the AI marks it valid, see parsed subject and recipients, preview the HTML, and verify the Outlook email arrives.
  13. Troubleshoot: If docs fail to load, check Google credentials and document IDs. If recipients are empty, revise the agent prompt to return labeled fields. If the contact is not found, confirm the Google Sheets column names and product to owner mapping.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

ERPNext

Sign up

Self-hosted (free): $0 / mo; Frappe Cloud shared hosting starts at $5 / mo

Google Docs

Sign up

Free: $0, Google Docs API usage at no additional cost (quota limits apply)

Google Sheets

Sign up

Free: $0 (Google Sheets API usage has no additional cost; quota limits apply)

Microsoft Outlook

Sign up

Exchange Online (Plan 1): $4.00 user / mo (annual billing)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Credits:
Developed by Amjid Ali
Email: amjid@amjidali.com
LinkedIn: https://linkedin.com/in/amjidali
Website: https://syncbricks.com
YouTube: https://youtube.com/@syncbricks
Course: http://lms.syncbricks.com
Support: http://paypal.me/pmptraining

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.