🔓 Unlock all 10,000+ workflows & prompts free Join Newsletter →
✅ Full access unlocked — explore all 10,000 AI workflow and prompt templates Browse Templates →
Home n8n Workflow
January 22, 2026

Gmail to MySQL, contacts logged without manual entry

Lisa Granqvist Partner Workflow Automation Expert

Inbox triage is one thing. But manually copying sender details into a database (or a “master contact sheet” that’s never quite right) is the kind of busywork that quietly wrecks your day.

Sales ops teams feel it when leads slip through cracks. Support managers feel it when handoffs are messy. And if you run a small team, you feel it because you’re the one doing the copy-paste. This Gmail MySQL logging automation keeps a clean contact trail without relying on someone’s memory.

You’ll set up an n8n workflow that watches for new Gmail messages, extracts sender/recipient details, and upserts a record in MySQL so duplicates don’t pile up.

How This Automation Works

Here’s the complete workflow you’ll be setting up:

n8n Workflow Template: Gmail to MySQL, contacts logged without manual entry

Why This Matters: Your “Contact Source of Truth” Keeps Drifting

If email is where leads, partner requests, and support issues start, then Gmail is effectively your front door. The problem is what happens after the email arrives. Someone has to log the sender, confirm the email address, connect it to an existing record, and keep it updated. That sounds simple until you’re doing it dozens of times a day across multiple teammates. A missed update creates duplicates. Duplicates create bad routing. Then someone replies to the wrong thread, or you lose context right when a customer is already annoyed. It’s death by tiny steps.

It adds up fast. Here’s where it breaks down in real teams.

  • New contacts sit in inboxes for hours because logging them “can wait,” and then it never happens.
  • Two people log the same sender under slightly different names, so your database turns into a duplicate factory.
  • Handoffs get sloppy because there’s no consistent record of who emailed whom, and what the subject line was.
  • Reporting becomes guesswork, because your “contacts” table isn’t updated when an existing sender emails again.

What You’ll Build: Auto-Log Gmail Senders Into MySQL (Deduped)

This workflow runs quietly in the background and turns every new Gmail email into a clean database record. It starts with a Gmail trigger that checks for new messages about once per minute. When an email arrives, a small code step pulls out the fields you actually care about for contact tracking: message and thread IDs, a snippet for quick context, sender and recipient names/emails, plus the subject when available. Then n8n writes that data into MySQL using an upsert pattern. If the sender email already exists, it updates the existing row instead of creating yet another duplicate. The result is a searchable, always-current contact trail that your team can query, join to tickets, or feed into reporting.

The workflow begins when Gmail sees a new email. Next, the email is normalized into consistent fields (names, emails, IDs). Finally, MySQL stores it in one table, updating existing senders so your data stays tidy.

What You’re Building

Expected Results

Say you receive about 40 important emails a day (leads, billing, support). If logging each sender takes roughly 2 minutes (copy name/email, paste, check duplicates, save), that’s about 80 minutes daily. With this workflow, the “human time” is basically zero after setup, because Gmail triggers the flow and MySQL updates automatically within about a minute. You get back over an hour most days, and your database stays consistent even when the inbox is chaos.

Before You Start

  • n8n instance (try n8n Cloud free)
  • Self-hosting option if you prefer (Hostinger works well)
  • Gmail for detecting and reading incoming emails.
  • MySQL to store and update your contact log.
  • Database table (create it in MySQL with required columns)

Skill level: Beginner. You’ll connect Gmail/MySQL credentials and match fields to the right database columns.

Want someone to build this for you? Talk to an automation expert (free 15-minute consultation).

Step by Step

A new email hits your Gmail inbox. The workflow’s Gmail trigger watches for new messages and checks about once per minute, so records stay fresh without you touching anything.

The message gets cleaned up into “database-ready” fields. A code step extracts sender and recipient names/emails, plus messageId, threadId, snippet, and subject (when it exists). This is where you enforce consistency, so “John Smith <[email protected]>” becomes predictable values.

MySQL stores the contact without creating duplicates. The MySQL node inserts the row the first time a sender appears, and updates it on future emails when the sender_email matches an existing record.

Your contact trail becomes queryable. From there you can build views, dashboards, or join it to tickets. Some teams also mirror the same dataset into spreadsheets for non-technical users.

You can easily modify what you store (like labels or timestamps) to match how your team qualifies leads or routes support. See the full implementation guide below for customization options.

Step-by-Step Implementation Guide

Step 1: Configure the Gmail Trigger

Set up the trigger so the workflow starts whenever a new email arrives in Gmail.

  1. Add the Incoming Email Trigger node to your canvas.
  2. Open Incoming Email Trigger and set Poll Times to everyMinute.
  3. Credential Required: Connect your gmailOAuth2 credentials.

Step 2: Connect MySQL

Prepare the database connection used to store sender and recipient details.

  1. Add the Upsert Contact Record node to your canvas.
  2. Credential Required: Connect your mySql credentials.
  3. Set Table to contacts.

Step 3: Set Up Data Processing with Code

Parse the email headers so sender and recipient details are extracted into clean fields.

  1. Add the Extract Sender Details node after Incoming Email Trigger.
  2. Set Mode to runOnceForEachItem.
  3. Paste the JavaScript into JavaScript Code exactly as provided in the workflow:
  4. // Extract Sender Info let sender_email = $json.From.trim(); let sender_name = null; if (sender_email.includes('<')) { sender_name = sender_email.split('<')[0].trim(); sender_email = sender_email.split('<')[1].replace('>', '').trim(); } // Extract Recipient Info let recipient_email = $json.To.trim(); let recipient_name = null; if (recipient_email.includes('<')) { recipient_name = recipient_email.split('<')[0].trim(); recipient_email = recipient_email.split('<')[1].replace('>', '').trim(); } return { "sender_name": sender_name, "sender_email": sender_email, "recipient_name": recipient_name, "recipient_email": recipient_email }

Step 4: Configure the Upsert Action

Map the extracted values into your database and upsert on message ID to avoid duplicates.

  1. Open Upsert Contact Record and set Operation to upsert.
  2. Set Column To Match On to messageId.
  3. Set Value To Match On to {{ $('Incoming Email Trigger').item.json.id }}.
  4. In Values To Send, add these mappings:
    • threadId{{ $('Incoming Email Trigger').item.json.threadId }}
    • sender_name{{ $json.sender_name }}
    • sender_email{{ $json.sender_email }}
    • recipient_name{{ $json.recipient_name }}
    • recipient_email{{ $json.recipient_email }}
    • subject{{ $('Incoming Email Trigger').item.json.Subject }}
    • snippet{{ $('Incoming Email Trigger').item.json.snippet }}

Tip: Ensure the contacts table has columns that exactly match the column names used in Upsert Contact Record to prevent insert errors.

Step 5: Test and Activate Your Workflow

Run a manual test to confirm data flows from Gmail into your database before turning it on.

  1. Click Execute Workflow and send a test email to your connected Gmail account.
  2. Verify Extract Sender Details outputs sender_name, sender_email, recipient_name, and recipient_email.
  3. Confirm a new row is created or updated in the contacts table by Upsert Contact Record.
  4. Toggle the workflow to Active to enable continuous monitoring.
🔒

Unlock Full Step-by-Step Guide

Get the complete implementation guide + downloadable template

Troubleshooting Tips

  • Gmail credentials can expire or lose access if your Google security settings change. If it stops triggering, check the Gmail credential in n8n and re-authenticate first.
  • If you’re using Wait nodes or external rendering, processing times vary. Bump up the wait duration if downstream nodes fail on empty responses.
  • MySQL inserts fail most often because the table schema doesn’t match the workflow fields. Confirm your columns exist (messageId, threadId, snippet, sender_name, sender_email, recipient_name, recipient_email, subject) and that nullable fields are actually nullable.

Quick Answers

What’s the setup time for this Gmail MySQL logging automation?

About 30 minutes if your Gmail and MySQL are ready.

Is coding required for this contact logging automation?

No. You’ll mostly connect accounts and map fields, and the included code step is already set up for you.

Is n8n free to use for this Gmail MySQL logging workflow?

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 your MySQL hosting cost (often already covered) since this workflow doesn’t require paid AI APIs.

Where can I host n8n to run this automation?

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.

Can I modify this Gmail MySQL logging workflow for different use cases?

Yes, and you probably should. You can extend the “Extract Sender Details” code step to include timestamps, Gmail labels, or attachment metadata, then add matching columns in MySQL. Some teams also store the support category they infer from the subject line, or tag “lead vs. customer” based on the recipient address. If you ever swap databases, you’d mainly replace the “Upsert Contact Record” MySQL step with the equivalent for your system.

Why is my Gmail connection failing in this workflow?

Usually it’s expired or revoked Google authorization. Reconnect the Gmail credential in n8n, then confirm the trigger is watching the right inbox and has permission to read new mail.

What volume can this Gmail MySQL logging workflow process?

For most small teams, it will handle daily email volume easily because it’s just one database write per message. On n8n Cloud, the practical limit is your plan’s monthly executions. If you self-host, there’s no platform execution limit, but your server and MySQL performance become the bottleneck. If you start processing huge inboxes or multiple mailboxes, consider filtering which labels/folders trigger the workflow so you only log the messages that matter.

Is this Gmail MySQL logging automation better than using Zapier or Make?

Often, yes, because deduping and upserting into a database is where “simple zaps” get awkward. n8n makes it easier to control the matching logic (like using sender_email) and to adjust the data before writing it. Zapier or Make can still work if you’re only logging a few fields and don’t care much about duplicates. If you’re unsure, Talk to an automation expert and we’ll help you pick the cleanest setup.

Once this is running, your inbox stops being a filing cabinet. Your MySQL contact trail stays current, and your team can focus on responding, not re-typing.

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.

Lisa Granqvist

Workflow Automation Expert

Expert in workflow automation and no-code tools.

×

Use template

Get instant access to this n8n workflow Json file

💬
Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Get a free quote today!
Get a free quote today!

Tell us what you need and we'll get back to you within one working day.

Launch login modal Launch register modal