n8n Mailgun Node Setup: Send CRM Lead Notifications via API
Set up the n8n Mailgun node to send instant CRM lead notification emails using Mailgun's REST API instead of SMTP. This step-by-step guide covers API credential configuration, the EU vs US region 401 error fix, and a complete webhook-to-email workflow for new lead alerts.
The n8n Mailgun node connects to Mailgun's REST API to send transactional emails from a workflow, no SMTP credentials required. You configure it with your Mailgun API key and domain, then pass dynamic lead data (such as name, email, and phone) into the email body using n8n expressions like {{ $json.body.email }}.
The most common issue in the n8n community when connecting to Mailgun is a 401 Forbidden error, almost always caused by using the wrong API domain. It has nothing to do with an incorrect API key, as confirmed by a 2025 n8n Community discussion on the Mailgun node. The actual cause is a one-field regional mismatch that takes about ten seconds to fix once you know where to look. This guide walks through the complete n8n Mailgun node setup for sending CRM lead notification emails, including that 401 fix and the exact webhook-to-email workflow we run in production at Rain Automation.
- The n8n Mailgun node uses Mailgun's REST API directly, not SMTP, which means faster delivery, built-in tracking, and no port-blocking issues from cloud providers.
- If your Mailgun account is on the EU region, you must select api.eu.mailgun.net in the n8n credential setup or every API call returns 401 Forbidden, even with correct keys.
- A complete webhook-to-Mailgun workflow in n8n takes three nodes: Webhook trigger, optional Set node for formatting, and the Mailgun node with dynamic expressions like {{ $json.body.email }}.
- Rain Automation runs this exact pattern (Mailgun API node for transactional CRM notifications) across 50+ production n8n workflows on a self-hosted instance.
Why the n8n Mailgun Node Is Different from the Send Email Node
The Mailgun node in n8n calls Mailgun's REST API directly using an API key and domain. The Send Email node connects over SMTP with a host, port, username, and password. These are two completely separate authentication and delivery paths, and picking the wrong one is a common source of confusion.
Here's why the distinction matters for CRM lead notifications specifically. Many cloud hosting providers (AWS, Google Cloud, Oracle Cloud) block outbound port 25 and throttle port 587, which is the standard SMTP path. The Mailgun API node sidesteps this entirely because it sends an HTTPS request to Mailgun's API endpoint, not an SMTP connection. No port issues, no TLS negotiation failures.
The API path also gives you delivery event data (delivered, bounced, opened, clicked) directly in Mailgun's dashboard, which the SMTP path does not expose in the same way.
Most n8n tutorials default to the Send Email node with SMTP credentials because it looks simpler on the surface. You paste a host, port, username, and password, and you're done. The problem is that ISPs and corporate firewalls block SMTP ports 25, 465, and 587 more aggressively every year, and cloud providers like AWS and Oracle Cloud block port 25 by default with no option to unblock it. The Mailgun REST API operates over port 443 (HTTPS), which is never blocked. For production CRM workflows where a missed lead notification costs real money, the extra five minutes of API credential setup is the obvious trade.
For SMTP or Gmail OAuth setup, see our n8n Send Email Node tutorial. This guide focuses entirely on the Mailgun API node.
| Feature | Mailgun Node (API) | Send Email Node (SMTP) |
|---|---|---|
| Auth method | API key + sending domain | SMTP host, port, username, password |
| Delivery tracking | Full event logs in Mailgun dashboard (opens, clicks, bounces) | No built-in tracking; requires separate analytics |
| Cloud port blocking | Not affected (HTTPS on port 443) | Often blocked on ports 25/465; throttled on 587 |
| Best for | Transactional CRM notifications, high-volume alerts | One-off emails, personal Gmail sends, low volume |
For CRM lead notification workflows where you need reliable, trackable delivery without SMTP port headaches, the Mailgun API node is the stronger choice. That's the path we use at Rain Automation across our n8n-powered automation stack.
What You Need Before You Start
You need three things to wire the n8n Mailgun node for CRM lead notifications: a Mailgun account with a verified sending domain, a running n8n instance, and a CRM or form tool that can fire a webhook. Getting all three in place before opening n8n saves you from stopping mid-build to create accounts or chase down API keys. Each component takes only a few minutes to set up on its own, but missing any one of them will block the workflow entirely.
Here's the checklist:
- Mailgun account with a verified sending domain (not the sandbox). Mailgun pricing varies by plan, so check mailgun.com/pricing for current rates. Create an account at mailgun.com.
- n8n instance, either self-hosted or n8n Cloud. Self-hosted gives you full control over credentials and networking. Cloud works too but adds a layer between you and your Mailgun API calls.
- A webhook source for new lead events. This can be HubSpot, a custom contact form, Typeform, Gravity Forms, or any CRM that supports outbound webhooks. If your CRM doesn't support webhooks natively, check our n8n HubSpot integration guide for workarounds.
One note on Mailgun's sandbox domain: it works for testing, but recipients must be pre-authorized in Mailgun's dashboard. For anything beyond initial testing, you'll want a verified custom domain.
Step 1: Get Your Mailgun API Key and Sending Domain
Your Mailgun API key lives under Settings > API Keys in the Mailgun dashboard, and your sending domain is listed under Sending > Domains. The critical detail most guides skip: you also need to know whether your account is on the US or EU region.
Here's how to find each piece:
- Log into app.mailgun.com (US) or app.eu.mailgun.com (EU)
- Go to Settings > API Keys
- Copy your Private API key (typically starts with
key-). This is the API key, not the SMTP password. Common mix-up: the SMTP credentials section on the same page shows a different password meant for SMTP connections. You don't need that one for the Mailgun node. - Go to Sending > Domains and note your verified domain (e.g.,
mail.yourbusiness.com)
Now the part that saves you an hour of debugging.
The EU vs US Region Gotcha That Causes 401 Errors
Mailgun operates two completely separate API endpoints:
- US region:
api.mailgun.net - EU region:
api.eu.mailgun.net
If you created your Mailgun account on the EU region (common for European businesses or anyone who clicked the EU option during signup), your API key only works against api.eu.mailgun.net. Calling api.mailgun.net with an EU key returns 401 Forbidden every time, even though the key itself is valid.
This is the single most common Mailgun error in n8n, and it's well-documented in the n8n community forums but poorly covered in official setup guides. The fix takes ten seconds once you know what's happening: switch the API Domain field in your n8n credential to api.eu.mailgun.net.
How to tell which region you're on: check the URL in your browser when you're logged into Mailgun. If it's app.eu.mailgun.com, you're on the EU region.
Step 2: Add Mailgun Credentials in n8n
In n8n, go to Credentials > Add Credential > search for "Mailgun API" and fill in three fields: API Domain, Email Domain, and API Key. Getting the API Domain wrong is what triggers the 401 error described above.
Walk through it:
- Open your n8n instance
- Click Credentials in the left sidebar
- Click Add Credential, then search for Mailgun API
- Fill in the three fields:
| Field | What to enter | Example |
|---|---|---|
| API Domain | api.mailgun.net (US) or api.eu.mailgun.net (EU) |
api.mailgun.net |
| Email Domain | Your verified sending domain from Mailgun | mail.yourbusiness.com |
| API Key | Your Private API key (typically starts with key-) |
key-abc123def456... |
- Click Save
A few things to double-check:
- The Email Domain field must match the verified domain exactly. If your Mailgun domain is
mail.yourbusiness.com, enteringyourbusiness.com(without themail.subdomain) will return a "Domain not found" error. - The API Domain dropdown is the EU/US region selector. If you're getting 401 errors with correct credentials, this field is almost certainly the problem.
- n8n stores credentials encrypted. You won't see the full key after saving.
Per n8n's Mailgun credential documentation, these are the only three fields required. No OAuth flow, no app registration. Simpler than most email integrations.
Step 3: Build the CRM Lead Notification Workflow
The workflow has three nodes: a Webhook trigger that receives new lead data from your CRM, an optional Set node that formats the payload, and a Mailgun node that fires the notification email. The whole thing takes about five minutes to build.
Here's the node-by-node setup.
Node 1: Webhook Trigger
Add a Webhook node as the trigger. Set the HTTP method to POST. Copy the Production URL (not the test URL) and paste it into your CRM's webhook settings for the "new lead" or "new contact" event.
The Webhook node receives the POST body from your CRM. A typical payload looks like this:
{
"body": {
"name": "Sarah Chen",
"email": "[email protected]",
"phone": "770-555-0142",
"source": "Website Contact Form",
"message": "Interested in a demo of your automation platform"
}
}
For details on how Webhook response modes affect downstream nodes, see our n8n Webhook Response Mode guide.
Node 2: Mailgun (Send Email)
Add the Mailgun node and connect it to the Webhook node. Select your Mailgun credential from the dropdown. Then configure the email fields:
- From:
[email protected](must match your verified Mailgun domain) - To: Your email address (or a team distribution list)
- Subject:
New Lead from {{ $json.body.source }}: {{ $json.body.name }} - Text: A plain-text version of the lead data (see Step 4 for the full template)
- HTML: A formatted version with the lead's details (see Step 4)
The key here is the n8n expression syntax. Every field inside double curly braces pulls from the Webhook node's output. Here are the specific expressions for a standard CRM lead payload:
{{ $json.body.name }} → Lead's full name
{{ $json.body.email }} → Lead's email address
{{ $json.body.phone }} → Lead's phone number
{{ $json.body.source }} → Where the lead came from
{{ $json.body.message }} → Any message the lead included
If your CRM sends the fields at the root level (without a body wrapper), the expressions become {{ $json.name }}, {{ $json.email }}, and so on. Test with a sample webhook to confirm the structure before building the email template.
So here's the thing about expression syntax in n8n: it's easy to get tripped up by nested objects. If your CRM sends { contact: { first_name: "Sarah" } }, the expression is {{ $json.contact.first_name }}. Use n8n's expression editor (the fx button next to each field) to browse the actual data structure after a test execution.
Node 3 (Optional): Slack or Teams Notification
If your team also uses Slack, add a Slack node after the Mailgun node to post to a #new-leads channel. This gives you push notifications on mobile without relying on email alone.
Step 4: Format the Lead Notification Email
Keep the HTML template simple. Heavy inline styling hurts deliverability, and Mailgun's transactional email processing works best with clean, lightweight HTML. Here's the template we use in production.
Paste this into the Mailgun node's HTML field:
<div style="font-family: Arial, sans-serif; max-width: 600px; padding: 20px;">
<h2 style="color: #333;">New Lead Received</h2>
<table style="width: 100%; border-collapse: collapse;">
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; font-weight: bold;">Name</td>
<td style="padding: 8px; border-bottom: 1px solid #eee;">{{ $json.body.name }}</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; font-weight: bold;">Email</td>
<td style="padding: 8px; border-bottom: 1px solid #eee;">{{ $json.body.email }}</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; font-weight: bold;">Phone</td>
<td style="padding: 8px; border-bottom: 1px solid #eee;">{{ $json.body.phone }}</td>
</tr>
<tr>
<td style="padding: 8px; border-bottom: 1px solid #eee; font-weight: bold;">Source</td>
<td style="padding: 8px; border-bottom: 1px solid #eee;">{{ $json.body.source }}</td>
</tr>
<tr>
<td style="padding: 8px; font-weight: bold;">Message</td>
<td style="padding: 8px;">{{ $json.body.message }}</td>
</tr>
</table>
<p style="color: #888; font-size: 12px; margin-top: 20px;">Sent by your n8n automation workflow</p>
</div>
For the Subject field, use a dynamic expression so you can tell leads apart in your inbox at a glance:
New Lead from {{ $json.body.source }}: {{ $json.body.name }}
And for the Text field (plain-text fallback):
New lead received:
Name: {{ $json.body.name }}
Email: {{ $json.body.email }}
Phone: {{ $json.body.phone }}
Source: {{ $json.body.source }}
Message: {{ $json.body.message }}
I had a client last year who was building out their first CRM automation and spent two hours debugging why the email body showed undefined for every field. The issue was that their form plugin sent data as {{ $json.fields.name }} instead of {{ $json.body.name }}. Moral of the story: always run a test execution first, click into the Webhook node output, and confirm the exact JSON path before building your template. Five minutes of testing saves hours of confusion.
Testing and Activating the Workflow
Use n8n's "Listen for Test Event" button on the Webhook node to fire a sample payload from your CRM or form, then verify the notification email arrives in your inbox before toggling the workflow to Active. The test execution runs every node in sequence so you can confirm that expressions resolve correctly and the Mailgun API accepts the request. Once the test email lands (check spam too), activate the workflow and it will process real leads automatically.
Step by step:
- Click Listen for Test Event on the Webhook node
- Submit a test lead through your CRM or form
- Once the Webhook node captures the payload, click Execute Workflow to run all nodes
- Check your inbox (and spam folder) for the notification email
- If the email arrived correctly, toggle the workflow to Active
But don't stop at n8n's execution log. Mailgun's own delivery logs give you a second verification layer that the SMTP path doesn't offer. Go to Sending > Logs in your Mailgun dashboard to see the delivery status, any bounce codes, and recipient engagement data for each message.
This matters for CRM notifications because a "successful" n8n execution only means the API accepted the request. Mailgun's logs tell you whether the email actually reached the inbox. If you see a dropped status, check your SPF and DKIM records.
Common n8n Mailgun Node Setup Errors and Fixes
Three errors account for the vast majority of Mailgun node failures in n8n. All three have straightforward fixes that take under a minute.
401 Forbidden (Even with Valid Credentials)
Cause: Your Mailgun account is on the EU region, but the n8n credential uses api.mailgun.net (the US endpoint).
Fix: Edit the Mailgun credential in n8n. Change the API Domain to api.eu.mailgun.net. Save and retry. This is the single most common Mailgun error in n8n, per n8n community reports.
Domain Not Found
Cause: The Email Domain field in the n8n credential doesn't match the verified domain in Mailgun exactly. If your Mailgun domain is mail.yourbusiness.com, entering just yourbusiness.com triggers this error.
Fix: Go to Mailgun > Sending > Domains, copy the full domain string, and paste it into the n8n credential's Email Domain field.
Email Goes to Spam
Cause: Missing or misconfigured SPF, DKIM, or CNAME records on your sending domain.
Fix: In Mailgun, go to Sending > Domains > [your domain] > DNS Records. Verify that all required records are published in your DNS. Mailgun shows green checkmarks for verified records and red Xs for missing ones. The most commonly missed record is the second DKIM key (k2._domainkey).
For more email troubleshooting beyond Mailgun-specific issues, see our n8n Send Email Node error fixes guide.
When to Use Mailgun vs SendGrid vs Gmail in n8n
For CRM lead notifications that need reliable, trackable delivery at scale, Mailgun's API node is the strongest option in n8n. Gmail works for small teams but hits rate limits fast. SendGrid sits in the middle with a higher free tier.
The Three-Path Email Decision
Before picking an email node in n8n, answer three questions: (1) Do you need API-level deliverability control and bounce tracking, or will basic SMTP do? (2) Are you already on a Google Workspace account with Gmail credentials ready to go? (3) Do you need transactional email receipts, open/click tracking, and webhook-based follow-up workflows? Your answers map to one of three paths. For a focused breakdown of the Send Email vs Gmail Node decision, see n8n Send Email vs Gmail Node: Which to Use for Your Workflow.
Here's a comparison across the criteria that matter for lead notification workflows:
| Criteria | Mailgun (API Node) | SendGrid (API Node) | Gmail (OAuth Node) |
|---|---|---|---|
| Free tier | Check mailgun.com/pricing for current plans | No permanent free plan (as of May 2025). 60-day trial at 100 emails/day, then paid from $19.95/month. See sendgrid.com/pricing. | 500/day (personal), 2,000/day (Workspace) |
| Auth in n8n | API key + domain | API key | OAuth 2.0 (more complex setup) |
| Delivery tracking | Yes (opens, clicks, bounces via dashboard + webhooks) | Yes (similar dashboard) | No built-in tracking |
| Cloud port blocking | Not affected (HTTPS) | Not affected (HTTPS) | Not affected (HTTPS) |
| Best CRM notification fit | High volume, developer-oriented, transactional | High volume, marketing + transactional | Low volume, personal accounts, simple alerts |
| Inbound email parsing | Yes (routes incoming emails to n8n via webhook) | Yes (Inbound Parse) | Not via n8n |
We covered the detailed comparison between n8n's Send Email node and the Gmail node in a separate post. If you're still evaluating which email path fits your CRM workflow, start there and then come back here for the Mailgun-specific setup.
Rain Automation's Production Setup
At Rain Automation, we run 50+ production workflows on a self-hosted n8n instance. For transactional CRM notifications (new lead alerts, deal stage changes, form submissions), we use the Mailgun API node rather than SMTP. The reasons come down to three things: no port-blocking issues on our Oracle Cloud infrastructure, delivery event tracking without extra tooling, and consistent sub-second API response times that keep workflow execution fast.
This isn't theoretical. Every contact form submission on rainautomation.com fires a Webhook-to-Mailgun workflow that follows the exact pattern described in this guide. If you want help setting up a similar workflow for your business, get in touch with our team.
For a deeper look at how we connect CRM tools to n8n workflows, check out our CRM automation setup guide.
Frequently Asked Questions
The questions below address the most common setup blockers for the n8n Mailgun node, drawn from real production configuration issues. Each answer is self-contained and does not require reading the full post for context.
Can I use Mailgun's SMTP credentials with n8n's Send Email node instead?
Yes. Mailgun provides both SMTP and API access. If you prefer the SMTP path, use the Send Email node with Mailgun's SMTP host (smtp.mailgun.org), port 587, and your Mailgun SMTP username and password. We cover SMTP setup in detail in our n8n Send Email Node tutorial. The API node described in this guide is typically more reliable on cloud-hosted n8n instances.
Why does my n8n Mailgun node return a 401 error with valid credentials?
The most common cause is a region mismatch. If your Mailgun account is on the EU region, you need to set the API Domain to api.eu.mailgun.net in the n8n credential. The default (api.mailgun.net) points to the US endpoint, which rejects EU API keys with a 401 Forbidden response.
What Mailgun plan do I need for n8n automation?
Mailgun pricing varies by plan, so check mailgun.com/pricing for current rates and plan options. For most small business CRM notification use cases, the entry-level paid plan provides more than enough volume. For testing, you can use Mailgun's sandbox domain at no cost, though recipients must be pre-authorized.
Does n8n support Mailgun webhooks for tracking opens and clicks?
Yes. Mailgun can send webhook events (delivered, opened, clicked, bounced, complained) to an n8n Webhook node. Set up the webhook URL in Mailgun under Sending > Webhooks, and n8n will receive event data for each email. This lets you build follow-up workflows triggered by recipient behavior.
Can I send from multiple Mailgun domains in one n8n workflow?
Yes. Create a separate Mailgun API credential in n8n for each sending domain. In your workflow, use different Mailgun nodes (each pointed to a different credential) depending on which domain should send the message. A Switch node before the Mailgun nodes can route based on lead source or notification type.
How do I test the Mailgun node without sending real emails?
Use Mailgun's sandbox domain (sandbox[hash].mailgun.org) and add your own email address as an authorized recipient. This lets you test the full workflow in n8n without affecting your production sending domain's reputation or deliverability metrics.
Some links on this page are affiliate links. Rain Automation may earn a commission at no extra cost to you.