Gmail to MySQL, leads captured and deduped
New lead comes in. You reply fast. Then the “easy” part shows up: finding the sender again later, logging them somewhere, and realizing your list has three versions of the same person.
This Gmail MySQL automation hits marketing ops teams hard, but agency owners tracking inbound inquiries and sales reps living in their inbox feel it too. You get a clean contact database that updates itself, even when names are missing or messy.
This workflow listens for new Gmail emails, extracts sender details, and upserts them into MySQL so you’re building a usable lead list while you work. You’ll see how it runs, what you need, and where teams usually trip up.
How This Automation Works
The full n8n workflow, from trigger to final output:
n8n Workflow Template: Gmail to MySQL, leads captured and deduped
flowchart LR
subgraph sg0["Receive Email Flow"]
direction LR
n0["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/mysql.dark.svg' width='40' height='40' /></div><br/>Insert New Client in MySQL"]
n1@{ icon: "mdi:play-circle", form: "rounded", label: "Receive Email", pos: "b", h: 48 }
n2["<div style='background:#f5f5f5;padding:10px;border-radius:8px;display:inline-block;border:1px solid #e0e0e0'><img src='https://flowpast.com/wp-content/uploads/n8n-workflow-icons/code.svg' width='40' height='40' /></div><br/>Extract Client Name and Email"]
n1 --> n2
n2 --> n0
end
%% Styling
classDef trigger fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
classDef ai fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef aiModel fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px
classDef decision fill:#fff8e1,stroke:#f9a825,stroke-width:2px
classDef database fill:#fce4ec,stroke:#c2185b,stroke-width:2px
classDef api fill:#fff3e0,stroke:#e65100,stroke-width:2px
classDef code fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
classDef disabled stroke-dasharray: 5 5,opacity: 0.5
class n1 trigger
class n0 database
class n2 code
classDef customIcon fill:none,stroke:none
class n0,n2 customIcon
The Problem: Your “Lead List” Lives in an Inbox
If inbound leads arrive through Gmail, your database is probably an accident. Someone copies names into a spreadsheet. Someone else exports contacts “later.” Meanwhile, the same person emails twice with different display names, or you get a reply from a shared domain alias, and your list turns into a junk drawer. It’s not just time. It’s the constant second-guessing: “Do we already have this contact?” and “Who owns this lead?” That uncertainty slows follow-ups and makes reporting feel impossible.
The friction compounds. Here’s where it breaks down in real life.
- You waste about 10 minutes per lead hopping between Gmail, a sheet, and a CRM just to capture basics.
- Duplicate contacts creep in, so segments and outreach lists get unreliable fast.
- Names are inconsistent (“John S.” vs “John Smith”), which leads to awkward personalization mistakes.
- When someone loses access to an inbox, you lose history and the “who contacted us” list along with it.
The Solution: Capture New Gmail Senders and Deduplicate in MySQL
This workflow turns your Gmail inbox into an always-updating lead intake channel. Every time a new email hits your inbox, n8n automatically grabs the sender details and cleans them up into a predictable format. It extracts the sender’s email address and tries to pull a usable name (and if the name isn’t there, it doesn’t invent one). Then it saves the contact into your MySQL database using an upsert approach: if that email already exists, the record gets updated instead of duplicated. You end up with one row per unique email, which is what most reporting and outreach systems actually need.
The workflow starts with a Gmail trigger that checks for new mail every minute. Next, a small processing step derives the sender name and email cleanly. Finally, MySQL inserts the contact or updates the existing record, keeping the email column unique so duplicates can’t silently pile up.
What You Get: Automation vs. Results
| What This Workflow Automates | Results You’ll Get |
|---|---|
|
|
Example: What This Looks Like
Say your agency gets 15 new inbound emails a day from website forms, referrals, and partnership intros. Manually saving each sender to a sheet or CRM at about 10 minutes each adds up to roughly 2.5 hours daily, and that’s before you dedupe. With this workflow, the “capture” time is basically zero: Gmail triggers the run, n8n extracts the sender, and MySQL stores or updates the record in the background. You check the database when you actually need it, and it’s already clean.
What You’ll Need
- n8n instance (try n8n Cloud free)
- Self-hosting option if you prefer (Hostinger works well)
- Gmail to trigger on new incoming emails.
- MySQL to store and dedupe contacts centrally.
- MySQL table (create columns: name (nullable), email (unique))
Skill level: Beginner. You’ll connect Gmail and MySQL credentials, then select the right table and columns.
Don’t want to set this up yourself? Talk to an automation expert (free 15-minute consultation).
How It Works
A new email arrives in Gmail. The workflow watches your inbox and checks for new messages about every minute, so leads don’t wait for someone to remember to “update the list.”
Sender details are normalized. n8n pulls the sender email and tries to derive a name from what Gmail provides. If there’s no name available, it stores a null value instead of dirty placeholders.
MySQL upserts the contact. The database write uses the email column as the unique identifier. If the email is new, it inserts a row. If it already exists, it updates the name so your record improves over time.
Your database becomes the source of truth. Now you can run outreach lists, domain analysis, or time-based reporting from MySQL instead of scraping your inbox history.
You can easily modify what you store (like subject, thread ID, or snippet) to support attribution and follow-up workflows. See the full implementation guide below for customization options.
Step-by-Step Implementation Guide
Step 1: Configure the Gmail Trigger
Set up the workflow to listen for new Gmail messages and kick off processing as soon as emails arrive.
- Add and open Gmail Intake Trigger.
- In Poll Times, confirm the schedule includes
everyMinute. - Credential Required: Connect your gmailOAuth2 credentials.
- Leave Filters empty if you want to capture all incoming emails.
Step 2: Connect MySQL for Contact Storage
Prepare the database connection so the workflow can upsert contacts into your MySQL table.
- Open Upsert Contact in MySQL and select your target database.
- Credential Required: Connect your mySql credentials.
- Set Table to
contacts.
Step 3: Set Up Sender Parsing Logic
Extract the sender’s name and email address from the Gmail payload so the database has clean fields.
- Open Derive Sender Details and set Mode to
runOnceForEachItem. - Paste the provided JavaScript into JS Code:
let email = $json.From.trim(); let name = null; if (email.includes('<')) { name = email.split('<')[0].trim(); email = email.split('<')[1].replace('>', '').trim(); } return { "name": name, "email": email }
⚠️ Common Pitfall: If your Gmail trigger data does not include a From field, the code will fail—verify the incoming payload when testing.
Step 4: Configure the MySQL Upsert Action
Map the parsed sender data into your database and ensure the upsert uses the email as the unique key.
- In Upsert Contact in MySQL, set Operation to
upsert. - Under Values to Send, map name to
{{ $json.name }}. - Set Column to Match On to
email. - Set Value to Match On to
{{ $json.email }}.
Step 5: Test and Activate Your Workflow
Validate the full flow from Gmail intake to database upsert, then turn it on for continuous capture.
- Click Execute Workflow and send a test email to the connected Gmail account.
- Confirm Derive Sender Details outputs
nameandemailfields. - Verify the contacts table is updated or inserted by Upsert Contact in MySQL.
- Toggle the workflow to Active to enable continuous processing.
Common Gotchas
- Gmail credentials can expire or lose permissions after a Google security change. If runs suddenly fail, check the Gmail credential status in n8n first and reconnect the account.
- If you’re processing a burst of emails (like after a campaign), execution timing can stack up. Give the workflow enough capacity (or adjust batching) so MySQL doesn’t receive overlapping writes that look like “random” errors.
- MySQL dedupe only works if your email column is truly UNIQUE and mapped correctly in the node settings. If the wrong column is selected, you’ll quietly create duplicates and only notice when outreach lists get weird.
Frequently Asked Questions
About 30 minutes if your MySQL table is ready.
No. You will connect Gmail and MySQL, then pick the right table and columns.
Yes. n8n has a free self-hosted option and a free trial on n8n Cloud. Cloud plans start at $20/month for higher volume. You’ll also need to factor in MySQL hosting costs if you don’t already have a database.
Two options: n8n Cloud (managed, easiest setup) or self-hosting on a VPS. For self-hosting, Hostinger VPS is affordable and handles n8n well. Self-hosting gives you unlimited executions but requires basic server management.
Yes, and it’s a practical upgrade. Add columns to your MySQL table (like subject, thread ID, message ID, or snippet), then in the “Upsert Contact in MySQL” node click “Add Value” and map the extra Gmail fields. Many teams also store the received date and recipient address so they can run cleaner reporting later.
Usually it’s expired authorization or a Google security change that invalidates the connection. Reconnect the Gmail credential in n8n, then confirm the trigger is pointed at the right mailbox and has permission to read new messages. If it still fails, check if the inbox is receiving mail in a way the trigger can see (filters and forwarding rules can be sneaky). Finally, review n8n’s execution log for the exact Google error message because it’s often specific.
On n8n Cloud Starter, you’re mainly limited by monthly executions; self-hosting removes execution limits but depends on your server. For a typical small business inbox volume, this workflow is lightweight because it only processes sender details and writes a single MySQL row per email. If you’re capturing thousands of emails a day, make sure your MySQL indexing is solid and consider batching or rate-limiting.
Often, yes. n8n makes the “upsert with unique email” pattern straightforward, and you can self-host for unlimited runs, which matters when you’re checking for new messages every minute. It’s also easier to extend later (for example, add enrichment via HTTP Request, or route certain senders to different tables) without paying per extra step. Zapier or Make can still be fine if you only need a basic two-step “new email → create row” and you don’t care about dedupe. If you’re unsure, Talk to an automation expert and map it to your volume and goals.
Once this is running, your inbox stops being your database. The workflow captures the repetitive stuff in the background, and you get a lead list you can actually trust.
Need Help Setting This Up?
Our automation experts can build and customize this workflow for your specific needs. Free 15-minute consultation—no commitment required.