Automated Gmail Sender Contact Sync to MySQL Database - n8n Workflow

Use this powerful n8n workflow to automatically extract sender information from incoming Gmail emails and upsert (insert or update) contacts into a MySQL database. Build robust mailing lists easily using this n8n template.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Sales and marketing agencies needing to automatically build lead lists from email correspondence.

  • Businesses requiring a reliable backup of all client contact information outside of their Gmail account.

  • Developers looking for an efficient n8n template for combining email triggers with relational database operations.

  • Users who need to synchronize new inbound contacts into a centralized database for CRM or mailing list purposes.

Overview

Manually logging new client or prospect contact details from incoming emails is time-consuming and error-prone. This specialized n8n workflow solves this inefficiency by automating the entire process. By utilizing a robust n8n node configuration, the system automatically captures sender names and email addresses from every new email received via the n8n trigger. The key benefit of this n8n automation is its use of the MySQL 'upsert' operation, ensuring that contacts are added only once (based on the unique email address) and updated if their details change. This n8n template is essential for anyone who values maintaining an accurate, real-time database of their email contacts.

How it Works

This automation initiates with the primary n8n trigger, the Gmail Trigger n8n node, which checks for new emails every minute.


  1. Triggering the Flow: The 'Receive Email' n8n trigger fires whenever a new email lands in the connected Gmail account.

  2. Data Extraction: The flow moves to the 'Extract Client Name and Email' n8n node, which is a custom code step. This node uses JavaScript to parse the complex 'From' header string (e.g., 'John Doe ') and cleanly isolate the sender's name and unique email address. If no name is provided in the header, the name field returns null.

  3. Database Upsert: The final step uses the 'Insert New Client in MySQL' n8n node. This MySQL n8n node performs an upsert operation (insert or update). It attempts to match the extracted email address against the 'email' column in the specified contacts table. If the email exists, it updates the 'name' field; if the email is new, it inserts a brand new contact record. This ensures the contact list remains unique and current. This complete n8n workflow operates reliably in the background.

Installation Guide

To set up this powerful n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON and import it into your n8n instance via the 'Workflows' section.

  2. Set up Gmail Credentials: Configure the 'Receive Email' n8n trigger node by creating or selecting an existing OAuth2 Gmail credential.

  3. Set up MySQL Credentials: Configure the 'Insert New Client in MySQL' n8n node by providing credentials for your MySQL database.

  4. Database Preparation: Before activating the n8n workflow, ensure you have a target table (e.g., contacts) in your MySQL database. This table must have an email column set as UNIQUE and a name column that allows NULL values.

  5. Configure MySQL Node: In the MySQL n8n node parameters, verify that the 'Table' is set correctly (e.g., contacts), the 'Column To Match On' is set to email, and the 'Values To Send' includes the name column mapping to the extracted {{ $json.name }}.

Node Details

Receive Email (Gmail Trigger n8n node):
Function: Serves as the starting n8n trigger, initiating the n8n workflow upon receipt of new emails.
Key Configuration: Polls for new messages using an 'everyMinute' setting.

Extract Client Name and Email (Code n8n node):
Function: Processes the raw 'From' field from the Gmail payload using custom JavaScript to extract clean, usable name and email variables.
Key Configuration: Uses a regex-like split operation to handle the standard email header format, ensuring data quality before database insertion.

Insert New Client in MySQL (MySQL n8n node):
Function: Handles the final data storage operation, performing an efficient 'upsert' to manage existing contacts and insert new ones.
Key Configuration:
Operation: upsert.
Table: contacts (or your defined table).
ColumnToMatchOn: email (ensures uniqueness and handles updates).
* ValueToSend: Maps the extracted name to the database name column.

Related n8n Workflows

Free

Nodes: 4 Nodes
Updated: December 26 2025
View all
Created by
Rosh Ragel
Rosh Ragel

Featured*