How to Automate New Lead Replies with n8n, Google Sheets and Gmail
Build a workflow that records new inquiries in Google Sheets and sends a Gmail acknowledgment. Learn the setup, duplicate checks, testing, and limits before using it.

A potential customer submits an inquiry while you are working on something else. Their message needs a place to live, and they need to know what happens next.
A small n8n workflow can handle those first steps: check the submission, save it in Google Sheets, and send an acknowledgment from Gmail. You can then review the inquiry and write a proper response yourself.
This guide covers that initial acknowledgment. It does not build a scheduled follow-up sequence, detect customer replies, or send repeated sales emails.
What this workflow does
The workflow uses an n8n form as its starting point. After someone submits it, the workflow:
- Checks the required fields.
- Looks for an existing inquiry with the same normalized email and message.
- Saves a new inquiry with an email status of
PENDING. - Sends one approved acknowledgment through Gmail.
- Updates the saved row with the send result and Gmail message ID.
An existing inquiry stops before the send step. A technical error also stops processing rather than allowing the workflow to continue with incomplete information.
This design suits a small, supervised inquiry process. It is not a complete CRM or a guarantee against every duplicate.
If your existing form already provides the acknowledgment and recordkeeping you need, an additional workflow may be unnecessary. n8n becomes useful when you need control over validation, tracking, and what happens between the form and the email.
What you need before starting
You need:
- An n8n environment you can configure.
- A Google account authorized to send the business’s replies.
- A Google Sheet accessible to the account used by the Sheets credential.
- An approved acknowledgment message.
- A test email address you control.
For ongoing use, n8n must remain running and the form must be reachable by your visitors. A workflow on your laptop stops being available when the application stops, the computer sleeps, or its connection becomes unavailable. Localhost is suitable for development; it is not a public hosting arrangement.
This tutorial does not require Gemini or another paid AI API. Hosting and account costs still depend on your setup.
Connect Google securely
Create separate Google Sheets and Gmail credentials inside n8n.
On n8n Cloud, supported Google nodes offer managed sign-in. Self-hosted installations require custom Google OAuth configuration. That involves enabling the relevant APIs, configuring consent, and registering the exact redirect URL shown by n8n. Google Sheets also requires the Google Drive API for this integration.
Follow the official Google OAuth setup instructions.
One detail matters for longer-running workflows: external Google OAuth applications left in Testing mode can encounter token expiry after seven days. A connection that works today should not be assumed to remain authorized indefinitely.
The account owner should complete authorization. Do not put passwords, client secrets, or access tokens into workflow code, email, screenshots, or a public repository.
Step 1: Create the lead-tracking sheet
Create a spreadsheet named Lead Reply Tracker, with a tab named Leads.
Add these column names across the first row, one name per column:
lead_idreceived_atfull_nameemailmessagededupe_keyemail_statusgmail_message_idsent_at
Use lead_id to identify a particular processing attempt. Use dedupe_key to recognize a repeated inquiry. They serve different purposes.
The proposed statuses are deliberately limited:
PENDING: the row was created, but the final send result has not been recorded.SENT: Gmail returned a successful send response.SENTdoes not mean the recipient opened the message or that it reached their inbox.
Keep the sheet private and give access only to people who need it. Avoid merged cells and additional headings inside the data area.
Step 2: Build the inquiry form
Add an n8n Form Trigger and name it Inquiry Form.
Create three required fields:
- Label Full name, field name
full_name, type Text. - Label Email, field name
email, type Email. - Label How can we help?, field name
message, type Textarea.
Use those field names exactly because the next step references them.
Set Respond When to Form Is Submitted. The form confirmation acknowledges receipt of the submission; it should not claim that the email was delivered or that the entire workflow succeeded.
Use the Test URL while building. The Production URL is for the saved, published workflow. Older n8n versions may use an activation control instead. See the Form Trigger documentation.
For initial tests, keep access restricted. Before exposing a form publicly, decide how you will control automated abuse. A required email field does not prove that the submitter owns that address.
Step 3: Validate and prepare the inquiry
Add a Code node after the form. Name it Prepare Lead, select JavaScript, and use Run Once for All Items.
The following proposed code expects one form submission per execution. It rejects invalid input before saving a row or calling Gmail.
const items = $input.all();
if (items.length !== 1) {
throw new Error('Expected one form submission.');
}
const input = items[0].json;
const fullName = String(input.full_name ?? '').trim();
const email = String(input.email ?? '').trim().toLowerCase();
const message = String(input.message ?? '').trim();
if (!fullName || fullName.length > 120) {
throw new Error('Enter a name between 1 and 120 characters.');
}
const singleEmail = /^[^\s@,;<>]+@[^\s@,;<>]+\.[^\s@,;<>]+$/;
if (email.length > 254 || !singleEmail.test(email)) {
throw new Error('Enter one valid email address.');
}
if (!message || message.length > 5000) {
throw new Error('Enter a message between 1 and 5000 characters.');
}
const normalizedMessage = message.replace(/\s+/g, ' ');
const dedupeKey =
encodeURIComponent(email) + ':' +
encodeURIComponent(normalizedMessage);
return [{
json: {
lead_id: String($execution.id),
received_at: new Date().toISOString(),
full_name: fullName,
email,
message,
dedupe_key: dedupeKey,
email_status: 'PENDING',
gmail_message_id: '',
sent_at: ''
}
}];This email check is a basic format check, not mailbox verification. The length limits are tutorial design choices; change them if your inquiry process needs different limits.
The duplicate key combines the normalized email and message. It is not encryption and contains customer information, so treat it as private data.
Keep the node’s error behavior set to Stop Workflow. Invalid submissions will require review in the execution history; this small workflow does not provide a separate customer-facing validation page.
Step 4: Check for an existing inquiry
Add a Google Sheets node named Find Existing Lead:
- Select Sheet Within Document → Get Row(s).
- Choose the Lead Reply Tracker document and Leads tab.
- Filter the
dedupe_keycolumn using{{ $('Prepare Lead').first().json.dedupe_key }}. - Keep the default first matching result.
- Under the node’s Settings, enable Always Output Data.
That last setting allows the next node to receive an empty item when no matching row exists. Keep On Error → Stop Workflow: a failed lookup must not be treated as “no duplicate found.” See n8n’s node settings.
Add an If node named New Inquiry?. Set a String → is empty condition on:{{ $json.lead_id ?? '' }}
Connect the true output to the next step. Leave the false output unconnected so an existing inquiry stops without sending another email.
This policy blocks the same normalized email and message for as long as the matching row remains in the sheet. A different message can proceed. A pending match needs investigation, not automatic resending.
There is also a concurrency limitation: two simultaneous submissions can both pass the lookup before either writes a row. Google Sheets does not make this check-and-write sequence atomic. Processes requiring strict duplicate prevention need stronger storage controls.
Step 5: Save the lead before sending
On the true branch, add a Google Sheets node named Save Lead.
Choose Append Row, select the same document and tab, and use Map Each Column Manually.
Map each header to its matching field from Prepare Lead. For example:
lead_id:{{ $('Prepare Lead').first().json.lead_id }}email:{{ $('Prepare Lead').first().json.email }}message:{{ $('Prepare Lead').first().json.message }}
Follow the same pattern for the remaining columns.
Use Cell Format → Let n8n format to preserve the input data types. Include a test with text beginning with = to confirm it is stored as text rather than evaluated as a spreadsheet formula.
Keep On Error → Stop Workflow. If saving fails, Gmail should not run.
The supported operations and mapping options are documented in Google Sheets node operations.
Step 6: Send a fixed acknowledgment
Add a Gmail node named Send Acknowledgment after Save Lead.
Configure:
- Resource: Message.
- Operation: Send.
- To:
{{ $('Prepare Lead').first().json.email }} - Subject: We received your inquiry.
- Email Type: Text.
Use Send, not Reply. A form submission is not an existing Gmail message with a message ID to reply to.
For the message, start with this fixed text:
Hello,
Thank you for your inquiry. This is an automatic acknowledgment that your message has been received.
Our team will review it and respond separately. If you need to add anything, you can reply to this email.
Make sure the sender’s inbox is monitored before inviting replies. If necessary, configure Send Replies To with the business’s monitored address. The Gmail node documentation explains these options.
Do not promise a response time that the business cannot consistently meet. Avoid quoting the submitted message or inserting customer-controlled links into this acknowledgment.
For this proposed setup, leave Retry On Fail off and keep On Error → Stop Workflow. A timeout does not always establish whether an email was sent. Blind retries can create duplicate messages.
Step 7: Record the successful send
After Gmail, add a Google Sheets node named Record Send Result.
Choose Update Row and match on lead_id, using:{{ $('Prepare Lead').first().json.lead_id }}
Update only:
email_status: SENTgmail_message_id: the actual message ID returned by Send Acknowledgmentsent_at:{{ $now.toISO() }}
If your Gmail node output contains the top-level field id, the message ID expression is:{{ $('Send Acknowledgment').first().json.id }}
Inspect your actual output before relying on that path. A successful Gmail API send returns a message resource; do not substitute a thread ID or invent a missing message ID. See Google’s send-message API reference.
Do not map blank values onto the other columns. After testing, inspect the saved row to verify that the original inquiry remains intact.
Test the workflow before relying on it
Use a separate test sheet and addresses you control. Run these checks before enabling customer submissions:
- Valid inquiry: Submit a new message. Check the saved row, the sender’s Sent folder, and the recipient’s inbox or spam folder. Confirm the message ID and status update.
- Repeated inquiry: Submit the same email and message again. It should stop at the duplicate branch without another email.
- Different inquiry: Use the same email with a different message. It should create a new record.
- Invalid input: Test missing or malformed values in a controlled development execution. Validation should stop before Sheets or Gmail.
- Spreadsheet text: Submit harmless text such as
=1+1. Confirm it remains literal text in the sheet. - Unavailable sheet: In a test copy, select an inaccessible sheet. Confirm Gmail does not run after the failure.
- Gmail failure: Use a deliberately unconfigured credential in a test copy. Confirm processing stops and does not mark the row
SENT. - Failure after sending: In a test copy, make only the final update fail. Check that the email can exist even while the sheet still shows
PENDING. Do not rerun the whole workflow to repair the row.
These are acceptance tests to perform, not results already demonstrated for this tutorial.
Once they pass, remove pinned test data, save and publish or activate the workflow, and test the Production URL once using your own address. Confirm that the production execution appears in n8n’s execution history.
Understand the failure cases
A pending row does not tell the whole story
A row can remain PENDING because Gmail was never called, the send outcome was uncertain, or the final spreadsheet update failed after a successful send.
Inspect the execution and available Gmail evidence before deciding what to do. An absent message in a quick inbox search is not conclusive proof that sending failed.
Repair a confirmed recordkeeping failure without sending the acknowledgment again
An automatic acknowledgment still needs supervision
Someone must review failed executions and unresolved pending rows. Start with a supervised pilot and agree who checks it.
For unattended operation, add and test a separate failure-notification workflow. n8n supports this through its error-handling features. An error notification should identify the execution; it should not automatically resend the customer’s email.
Sending is subject to account limits and delivery conditions
Gmail can reject or restrict sending, and accepted messages can still bounce or land in spam. Check the current limits for your account rather than assuming one allowance applies to every Gmail and Workspace account.
Google documents Gmail sending restrictions. This workflow is for acknowledgments to incoming inquiries, not bulk outreach.
Protect customer information and the sender account
Collect only the details needed to answer the inquiry. Do not ask customers to submit passwords, payment-card details, or sensitive documents through this basic form.
Remember that customer information can appear in both Google Sheets and n8n execution history. Limit access, set an appropriate retention policy, and remove personal information from screenshots.
Before public use, address form abuse. An attacker can submit someone else’s address repeatedly; a different message would also bypass this tutorial’s exact-inquiry duplicate rule. Rate limits, appropriate bot protection, or a reviewed intake process may be needed. n8n’s Ignore Bots option alone is not comprehensive abuse prevention.
Keep inquiry acknowledgments separate from marketing subscriptions. Do not quietly turn a contact-form submission into an ongoing email campaign.
What my larger project adds
In my AI Lead Qualification & Follow-up project , I implemented structured AI extraction, deterministic scoring, email checks, a review queue, and a separate error handler.
The documented tests include a successful Gmail send and CRM update, along with failure cases around the email step. That project taught me to track email outcomes separately from overall processing success: a CRM failure after sending should not be treated as proof that the email failed.
Those patterns informed this guide. They are not all implemented in the simplified configuration above. The project repository contains the fuller implementation and documentation.
Need help adapting this to your inquiry process?
If you would like help setting up a small inquiry acknowledgment workflow, email me at saadkabeer.ai@gmail.com with your form source, Google account setup, and whether you already have a running n8n environment.
I’ll review the requirements before confirming whether I can help, the delivery scope, and a price. Hosting, ongoing monitoring, and advanced integrations would need to be agreed separately.