Connecting Mailgun to Salesforce
Mailgun is developer-facing email infrastructure, which means the sending logic lives in your application and the marketing team frequently does not know what is being sent or when. Sending conversions into Salesforce rather than out of it is how marketing data reaches the place sales actually works. The join between them succeeds or fails on one thing: whether the Lead or Contact identity reaches the Mailgun message before the conversion happens, because Salesforce can only match a conversion it can tie back to a click it recognizes.
Free30 minutesNo obligation
Specific to this pair
Mailgun activity in Salesforce: bounces and key sends only
Attach the Salesforce Lead or Contact ID to each Mailgun message as a custom variable for the webhook handler. Flag permanent failures and spam complaints on the record, and log only sales-relevant sends, like trial ending, as activities with a trigger reason and clear source. Skip a Task per delivery, and test field-level security with a real record.
This pair comes up in B2B SaaS: product and trial emails go out through Mailgun from application code, sales works in Salesforce, and reps want to know what a prospect has been sent. The join key is the Salesforce Lead or Contact ID, attached to each message as a Mailgun custom variable so the webhook handler can find the record without guessing by email address.
Resist writing every webhook event into Salesforce. A Task for each delivery and open fills the activity timeline with noise and uses data storage you pay for. Write two kinds of thing. Permanent failures and spam complaints should flag the email as bad on the Lead or Contact so reps stop using it. And a short list of sends that matter to a sales conversation, such as trial ending or usage limit reached, can be logged as activities with the trigger reason.
Test field-level security and validation rules with a real record; a bounce flag the integration user can't write returns success at the API and changes nothing. Marketing email sent from Salesforce or a marketing tool may already log its own activity, so add Mailgun activity alongside it with a clear source value. A rep should be able to tell an application email from a campaign at a glance.
Mailgun → Salesforce · what breaks
Why this join usually fails — Mailgun → Salesforce
- 01
The Lead or Contact identity never reaches Mailgun
No session, no click, and the trigger conditions are buried in application code rather than in a campaign tool.
- 02
Nobody able to say why a message was sent
When send logic lives in application code, the marketing team cannot audit it and the engineering team is not thinking about attribution. Messages accumulate, nobody owns the list, and any analysis of email's contribution is unreliable.
- 03
Writes that succeed and change nothing
Field-level security, validation rules and required-field constraints can reject a write while the API reports success. Open the record and look rather than trusting the response.
- 04
Nothing reconciles afterwards
Check the record in Salesforce itself, not the API response. Then confirm the value survives Lead conversion onto the Contact, Account and Opportunity — the mapping is separate and is usually the thing that was missed.
Mailgun → Salesforce · the fix
What working looks like — Mailgun → Salesforce
The Lead or Contact identity on every message
Conversions arriving in Salesforce
The marketing context appears on the record and flows into the opportunity, where sales and reporting can both use it.
Reconciled against the source
Mailgun → Salesforce · architecture
How Mailgun and Salesforce actually connect
- 1
Mailgun holds the truth
Because sends are triggered in code, the only reliable description of why a message went out lives in your application, not in Mailgun's logs.
- 2
Salesforce needs a click to match
Salesforce needs a resolvable record and a custom field to write to. Field-level security and validation rules can silently reject writes, which is a Salesforce-specific failure that returns success at the API level and changes nothing.
- 3
The identifier is the bridge
The Lead or Contact identity, captured at the visit and carried into the Mailgun message.
- 4
The event source decides reliability
Send orders. Use Mailgun events for deliverability monitoring only.
- 5
Deduplication at the destination
Salesforce deduplicates according to whatever matching rules your org has configured, which vary enormously between instances. Duplicate Leads are the standard failure and merging them afterwards is manual work.
Mailgun → Salesforce · normal or broken
Working vs. broken, side by side — Mailgun → Salesforce
Normal, not a fault
The Lead or Contact identity present on the message
Sent from your order system
Deduplicated correctly
Salesforce deduplicates according to whatever matching rules your org has configured, which vary enormously between instances. Duplicate Leads are the standard failure and merging them afterwards is manual work.
Reconciles with the source
Actually broken
The Lead or Contact identity missing on most records
No session, no click, and the trigger conditions are buried in application code rather than in a campaign tool.
Sent from the browser
When send logic lives in application code, the marketing team cannot audit it and the engineering team is not thinking about attribution. Messages accumulate, nobody owns the list, and any analysis of email's contribution is unreliable.
Counted twice, or not at all
Field-level security, validation rules and required-field constraints can reject a write while the API reports success. Open the record and look rather than trusting the response.
Nobody has reconciled it
Mailgun → Salesforce · diagnose
Diagnostic order — Mailgun → Salesforce
- 01
Count messages carrying the Lead or Contact identity
- 02
Follow one real conversion end to end
- 03
Inventory every code path that triggers a send
Usually the first time anyone has, and it frequently finds sends nobody remembers building.
- 04
Write a test value and open the record in the UI
The API saying it worked and the field actually holding the value are different things in Salesforce more than anywhere else.
- 05
Read the match rate, not the success message
Check the record in Salesforce itself, not the API response. Then confirm the value survives Lead conversion onto the Contact, Account and Opportunity — the mapping is separate and is usually the thing that was missed.
Mailgun → Salesforce · prove
How it gets proven — Mailgun → Salesforce
Source of truth
Your application's own record of what triggered the send, joined to the order.
- The Lead or Contact identity confirmed present on a live message.
- A test value confirmed present on the record in the UI, and confirmed to survive Lead conversion.
- Orders reconciled against imported conversions, with the send inventory documented.
Mailgun → Salesforce · free audit
What we check in the free audit
- Count messages carrying the Lead or Contact identity
- Follow one real conversion end to end
- Inventory every code path that triggers a send
- Write a test value and open the record in the UI
- Read the match rate, not the success message
Checked against
Your application's own record of what triggered the send, joined to the order.
Free30 minutesNo obligation
Mailgun → Salesforce · when not to buy
When you don't need this — Mailgun → Salesforce
- Measure identifier coverage yourself first — pull your last hundred messages and count how many carry the Lead or Contact identity.
- Deliverability monitoring is the right use of Mailgun's data. Attribution belongs at the order.
- If your Salesforce org is administered by a team you cannot get time with, scope their availability before starting — this build is usually blocked on admin access rather than on the work.
Mailgun → Salesforce · what we deliver
What gets built — Mailgun → Salesforce
Identifier capture into Mailgun
Record the trigger reason on the message in your own system and attribute at the order.
Event source: your order system
Send orders. Use Mailgun events for deliverability monitoring only.
Dispatch to Salesforce
API writes to the Lead or Contact record, or a platform event, carrying the marketing context as custom field values.
Reversals where they exist
Refunds reverse at the order.
Written guarantee
95%+ tracking accuracy
Measured against Your application's own record of what triggered the send, joined to the order.. Miss it and we keep working at no cost.
From $400 · See packages
FAQ
Mailgun → Salesforce questions, answered
Yes, by receiving Mailgun webhooks and writing to Salesforce through its API, with the record ID passed as a custom variable on each message. Log only bounces, complaints and the sends sales actually needs.
Handle Mailgun's permanent failure webhook and set a bounce flag on the matching Lead or Contact. Confirm in the Salesforce UI that the field actually changed.
Almost always because the Lead or Contact identity never reached the Mailgun message. No session, no click, and the trigger conditions are buried in application code rather than in a campaign tool. Measure coverage before debugging the dispatch.
Salesforce resolves on its own record identity — a Lead, a Contact, or an Account — rather than on a click identifier. What you are doing here is attaching marketing context to a record so the pipeline carries it, which means the click identifier arrives as a custom field value rather than as a matching key. The hazard is duplicates: two Leads for one person means two records with half the history each.
Your order system. Send orders. Use Mailgun events for deliverability monitoring only.
Check the record in Salesforce itself, not the API response. Then confirm the value survives Lead conversion onto the Contact, Account and Opportunity — the mapping is separate and is usually the thing that was missed.
More on Mailgun → Salesforce
- Mailgun → Marketing CloudConnecting Mailgun to Salesforce Marketing Cloud
- Salesforce → Google AdsConnecting Salesforce to Google Ads
- Salesforce → MetaConnecting Salesforce to Meta Conversions API
RELATED GUIDES
Where Mailgun → Salesforce fits in the rest of your tracking
- Postmark → SalesforceConnecting Postmark to Salesforce
- SendGrid → SalesforceConnecting SendGrid to Salesforce
- Resend → SalesforceConnecting Resend to Salesforce
- Mailgun → MarketoConnecting Mailgun to Marketo
- Mailgun → HubSpotConnecting Mailgun to HubSpot
- SaaSConversion tracking for SaaS, from signup through to the payment that matters
Free · 30 min
Get Mailgun and Salesforce joined properly
Free30 minutesNo obligation
