Internative Logo

What Is Mailgun? The Email API for Transactional Email

What Is Mailgun? The Email API for Transactional Email

Almost every application sends email: sign-up confirmations, password resets, invoices, alerts. Sending one message from a server is easy. Making sure thousands of them reach the inbox, not the spam folder, is not. It takes authenticated domains, a sender reputation that mailbox providers trust, handling of bounces and complaints, and a record of what happened to every message. Mailgun is a service that takes that work off the application: you call an API, and Mailgun delivers, tracks and reports.

This article explains what Mailgun is, how it works, where it fits, when another option is better, and how it compares with the alternatives.

What is Mailgun?

Mailgun is a cloud email delivery service built for developers. Applications use its HTTP API or SMTP relay to send transactional and bulk email, and its routing features to receive and process incoming mail. Around sending it adds delivery tracking, webhooks, suppression lists, email address validation and deliverability tools.

Ev Kontsevoy and Taylor Wakefield founded Mailgun in 2010, and the team announced the launch of the product on 29 October 2010. The company went through Y Combinator's Winter 2011 batch and was acquired by Rackspace in 2012. In 2017 it was spun out of Rackspace as an independent company, and in 2019 it acquired Mailjet, a European email provider. Mailgun and Mailjet later became brands of Pathwire, and Sinch, a communications platform company, agreed to acquire Pathwire in September 2021 and completed the deal on 7 December 2021. That is why the product now appears as Sinch Mailgun.

How Mailgun works

A verified sending domain. You add a domain, usually a subdomain such as mg.example.com, and publish the DNS records Mailgun gives you. SPF and DKIM let mailbox providers verify that Mailgun may send on your behalf and that messages were not altered, and a DMARC policy tells them what to do with mail that fails those checks. Domains can be created in Mailgun's US or EU region.

Sending by API or SMTP. The application sends a message with an HTTP request or through Mailgun's SMTP relay, which is useful for software that only speaks SMTP. Messages can use stored templates with variables, so the content lives in one place and the code only passes data. Official SDKs exist for languages including Python, Go, Node.js, PHP, Java and Ruby.

Events and webhooks. Every message produces events as it moves: accepted, delivered, temporary failure, permanent failure, opened, clicked, unsubscribed and complained. Mailgun can post each event to your endpoint as a webhook, so the application can mark an address as invalid or show a delivery status without polling.

Suppressions. Addresses that bounce permanently, unsubscribe or mark a message as spam are added to suppression lists, and Mailgun stops sending to them. This protects the domain's reputation, which is what decides whether future mail reaches the inbox.

Inbound routes. Mailgun can also receive mail for your domain. Routes match incoming messages by rules and either forward them to an address or post them, parsed, to your application. This is how reply-by-email, support inboxes and email-to-ticket features are built.

Key features

  • Send: the email API and SMTP relay, with templates and tracking of opens and clicks.
  • Validate: email address validation, for single addresses at sign-up or for whole lists before a campaign.
  • Optimize: deliverability tools, including inbox placement testing.
  • Inspect: previews of how an email renders across email clients and devices, with checks for errors and accessibility issues.
  • IP pools and dedicated IPs on larger plans, so a high-volume sender's reputation is not shared with others.
  • US and EU regions for teams that need data to stay in a given region.

Where Mailgun is used

  • Transactional email in SaaS products: verification codes, password resets, receipts and notifications. Our guide to building a SaaS product covers where these pieces fit in a product's first release.
  • System alerts and reports sent by backend jobs and monitoring tools.
  • Bulk and newsletter sending for teams that prefer an API over a marketing tool.
  • Inbound processing, such as support inboxes, replies to notifications and email-to-ticket flows.
  • Sign-up forms, where address validation catches typos and disposable addresses before they enter the database.

When to choose Mailgun, and when not to

Choose Mailgun when:

  • Email is a critical part of the product and you want delivery events, logs and suppressions without building them.
  • Developers will integrate it, and an API with webhooks matters more than a drag-and-drop editor.
  • You need inbound email as well as outbound.
  • You want to keep data in the EU region.

Look elsewhere when:

  • The work is mainly marketing campaigns run by a marketing team. A marketing platform with audience management and a visual editor is a better fit.
  • Your stack already runs on AWS and you need low-cost, high-volume sending with minimal features. Amazon SES is simpler and leaves more of the tooling to you.
  • You need to keep all mail on your own servers. A self-hosted mail server is possible, but you take on IP reputation, blocklists and deliverability yourself.
  • You send a handful of messages a day from an internal tool. Your existing mail provider's SMTP may be enough.

Whichever provider you choose, deliverability depends on your own practice as much as on the service: authenticate the domain, send only to people who asked for the mail, and keep transactional and marketing traffic on separate subdomains so a campaign cannot damage password-reset delivery.

Mailgun and its alternatives

ServiceOwnerStrengthBest fit
MailgunSinchDeveloper API, inbound routes, validationProducts where email is part of the application
SendGridTwilioAPI plus marketing campaignsTeams that want both in one platform
Amazon SESAWSLow-level, pay-per-use sendingHigh volume on AWS with in-house tooling
MailjetSinchMarketing editor with an APIMarketing-led teams, especially in Europe
Self-hosted (Postfix)YouFull controlStrict on-premise requirements

SendGrid is the most common comparison. Both are mature developer email APIs; SendGrid, part of Twilio since 2019, puts more weight on marketing campaigns next to its API, while Mailgun's strengths are inbound routing, validation and deliverability tooling. Amazon SES is the low-level option: inexpensive and reliable, but with fewer built-in tools around sending.

How we use Mailgun at Internative

We use Mailgun to build reliable, scalable email flows into our products. Its API-first design and deliverability tools let us run critical system emails with confidence.

If your product needs dependable transactional email, our SaaS design and development and system integration teams can help you set up the sending, tracking and inbound flows around it.

Frequently asked questions

What is Mailgun used for?

Mailgun is used to send email from applications: account verification, password resets, receipts, notifications and bulk messages. It is also used to receive and parse incoming email, to validate addresses and to track what happened to every message through events and webhooks.

Is Mailgun not free anymore?

Mailgun still offers a free plan, limited to 100 emails a day, which suits testing and very small projects. Production sending is on paid monthly plans tiered by email volume, with custom contracts for large senders.

What is Sinch Mailgun?

It is the same Mailgun. Sinch completed its acquisition of Pathwire, the parent of Mailgun and Mailjet, in December 2021, and the product has carried the Sinch name since then. The API, the dashboard and the service work as before.

Mailgun or SendGrid?

Both are reliable developer email services. Choose Mailgun if inbound routing, address validation and deliverability tools matter most; choose SendGrid if you also want marketing campaigns in the same platform. In practice, domain authentication and sending habits affect deliverability more than the choice between the two.

Related services

Where this topic becomes an engagement.

Keep reading

The articles that follow this one.