Automate Mautic Unsubscribe Handling with Gmail & n8n

This n8n workflow automates unsubscribing contacts in Mautic triggered by automated unsubscribe emails in Gmail. It efficiently updates contact segments and replies to unsubscribe requests, saving time and reducing manual errors.
gmailTrigger
if
code
+4
Workflow Identifier: 2464
NODES in Use: Gmail Trigger, IF, Code, Mautic, Gmail, Set, Sticky Note
Automate Mautic unsubscribes with Gmail and n8n

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow watches a Gmail inbox for unsubscribe emails and automates removing those emails from active mailing lists in Mautic.
It finds the sender’s email, checks Mautic for that contact, moves the contact to an unsubscribed group, and replies to confirm the opt-out.
This stops email clutter, saves time, and keeps unsubscribe requests handled correctly.


Who should use this workflow

This workflow is for marketing managers or anyone running email campaigns with Mautic.
It helps when unsubscribe emails come in high volume and cause manual work or mistakes.
Users must have a Gmail account with OAuth2 and a Mautic account with API access.


Tools and services used

  • Gmail with OAuth2: receives and replies to unsubscribe emails.
  • Mautic with OAuth2: accesses contact information and updates segments.
  • n8n automation platform: runs the workflow every minute to manage emails and API calls.
  • Optional self-host n8n: for users wanting full control, running on servers like self-host n8n.


Workflow inputs, processing steps, and outputs

Inputs

  • New unsubscribe emails arrive in Gmail inbox.
  • From field and To field to identify and extract sender email.
  • Configured email address and message templates in the workflow.

Processing steps

  • Check if emails are unsubscribe requests using filters on To and From fields.
  • Extract clean sender email addresses with JavaScript.
  • Remove repeated emails so each contact is processed once.
  • Search Mautic for contact matching the email address.
  • Verify that the contact exists before updating.
  • Add contact to unsubscribed segment and remove from active newsletter segment.
  • Reply politely to the original email confirming unsubscribe success.

Outputs

  • Subscriber is removed from active mailing list in Mautic.
  • Subscriber is added to unsubscribed segment in Mautic.
  • Sender receives confirmation reply email from Gmail.
  • Workflow logs show processed emails and updates.


Beginner step-by-step: Running this workflow in n8n

1. Import the workflow

  1. Download the workflow JSON file using the Download button on this page.
  2. Open your n8n editor where workflows are created.
  3. Click “Import from File” and select the downloaded JSON file to load the workflow.

2. Configure credentials and settings

  1. Add your Gmail OAuth2 credentials in the Gmail Trigger and reply nodes.
  2. Add your Mautic OAuth2 credentials in all Mautic API nodes.
  3. Update your Gmail email address and unsubscribe confirmation message in the Edit Fields node.
  4. Check segment IDs in Mautic and update them in the nodes for adding/removing segments.

3. Test and activate

  1. Send a test unsubscribe email to your Gmail to verify the workflow triggers.
  2. Check the workflow execution log to confirm contact lookup, segment changes, and reply email.
  3. Once happy, activate the workflow using the button in n8n to run every minute.

Key code snippets explained

The following JavaScript extracts sender email in the Extract Email from ‘From’ Field node:

var fromField = $input.item.json.From;
var extractedEmail;
if (fromField.includes('<') && fromField.includes('>')) {
  var regex = /[^< ]+(?=>)/g;
  extractedEmail = fromField.match(regex)[0];
} else {
  extractedEmail = fromField;
}
return {json: {extractedEmail}};

This code reads the From field and finds the email inside angled brackets or uses the full value if brackets are missing.
The output is a clean email string used for searching Mautic.

The following JavaScript in Extract Unique Email Addresses removes duplicates:

const inputData = $input.all();
const uniqueEmailsSet = new Set();
inputData.forEach(item => {
  uniqueEmailsSet.add(item.json.extractedEmail);
});
const uniqueEmailsArray = Array.from(uniqueEmailsSet).map(email => {
  return { json: { extractedEmail: email } };
});
return uniqueEmailsArray;

This collects all extracted emails and returns only one instance per email to avoid repeated steps.


Customization ideas

  • Change the unsubscribe reply message by editing the unsubscribeMessage in the Edit Fields node.
  • Update segment IDs in the Mautic nodes to match your account setup.
  • Enable the “Do Not Contact List” node for stricter unsubscribe rules.
  • Adjust the polling frequency in the Gmail Trigger node to suit your email load.
  • Add new conditions in the unsubscribe filter node to catch more email formats.


Troubleshooting tips

  • If Mautic nodes show “No credentials returned” error, re-add your OAuth2 credentials.
  • If the Gmail Trigger misses emails, check API limits and those emails aren’t in Spam or Trash.
  • If segments don’t update, verify Mautic segment IDs and user API permission.


Pre-Production checklist

  • Test Gmail OAuth2 with real unsubscribe emails.
  • Verify successful Mautic contact queries with test emails.
  • Confirm segment IDs match Mautic dashboard settings.
  • Send test unsubscribe emails to ensure extraction and replies work.
  • Backup workflows and important Mautic data before live deployment.


Deployment instructions

After testing, activate the workflow in n8n for live processing.
Monitor the executions for errors and adjust poll frequency to avoid API limits.
Consider adding alerts or logging for error handling.


Summary

✓ Automates processing unsubscribe emails in Gmail.
✓ Updates contact segments in Mautic without manual work.
✓ Sends confirmation replies to unsubscribing contacts.
✓ Saves user time and reduces errors.
✓ Maintains GDPR and unsubscribe compliance.
→ Efficient email list management through automation.
→ Clear contact updates and professional communication.
→ Easy to configure and extend in n8n.


Automate Mautic unsubscribes with Gmail and n8n

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

No. This workflow uses Gmail Trigger and reply nodes requiring Gmail OAuth2 credentials. Outlook would need different nodes and adjustments.
No. It makes minimal API calls per unique email and usually runs every minute, suitable for most Mautic plans.
Yes. OAuth2 ensures secure communication. Only necessary data is processed temporarily for unsubscribe automation.
Yes. With proper polling settings and server resources, n8n can manage high volumes. Consider batching if volume grows significantly.
Author
Written By
Vikash Kumar
Building AI agents, n8n workflows and end-to-end automation for 30+ Brands across India, the US, Europe, Dubai & Australia. 7+ years of Experience saving founders real hours every week - no code required.

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.