1. Code
  2. Email

Exploring Mailgun: The Email Engine for Developers

Sponsored Content

This sponsored post features a product relevant to our readers while meeting our editorial guidelines for being objective and educational.

What You'll Be Creating

Why Developers Should Explore Mailgun

If you're not yet familiar with Mailgun, it's the email automation engine trusted by over 10,000 website and application developers for sending, receiving and tracking emails. By taking advantage of Mailgun's powerful email APIs, developers can spend more time building awesome websites and less time fighting with email servers.

Exploring Mailgun - Chris Hexton CEO Vero Testimony

What Features Does Mailgun Offer?

Mailgun's API supports all of the most popular languages including PHP, Ruby, Go, Python, C# and Java, and they offer excellent, well-organized documentation.

There's also an excellent Mailgun plugin for WordPress which helps you link your website to your Mailgun service.

Exploring Mailgun - The Email Automation Engine Logo

How Much Does Mailgun Cost?

Mailgun is accessible to developers testing and running production environments. The basic account is free for up to 10,000 messages monthly. Mailgun is integrated into Rackspace Cloud, Heroku and Google App Engine. 

Overall, pricing is a usage-based, monthly subscription, e.g. 100,000 emails is only $45 per month. Usage is based on outbound messages and the number of dedicated IP addresses used. There is no charge for inbound messages.

You can estimate your costs using the Mailgun pricing calculator:

Exploring Mailgun - Pricing Calculator

What This Tutorial Covers

In this tutorial, I'll give you a high-level walkthrough of Mailgun and its key services so you can discover the benefits that it can offer your company, startup or individual projects.

While this is a sponsored piece, I've been a genuinely enthusiastic Mailgun developer for several years. I've written Mailgun-centered blog posts for the company and Envato Tuts+ and added the list subscription functionality to their WordPress plugin last year.

I'm especially interested in your experience with Mailgun or if you want to suggest topics related to email for future tutorials. Please post them below in the comments and of course, you can reach me on Twitter @reifman.

Exploring Mailgun's Features

Quick and Easy Signup

It's simple to get started with Mailgun. To explore Mailgun as you read along with us, sign up here:

Exploring Mailgun - Sign Up Form

You'll be provided API keys and asked to authenticate ownership of your domain(s) with DNS updates.

Exploring Mailgun - Domain Example in the Control Panel

These make it easy to get started sending private-label emails powered by Mailgun.

Managed Email Services

While many people use Mailgun directly as developers, Mailgun also offers a turnkey managed email service for companies interested in having the difficult aspects taken care of for them.

Exploring Mailgun - Markus Hanel ZenMate Co-Founder Testimonial

Sending tens of millions or hundreds of millions of emails a month requires an extra level of diligence to maintain a positive sending reputation. A single misstep can send a big part of your email to spam. Mailgun's managed email service keeps your company's reputation intact—in turn, this ensures that most all of your customers are receiving your emails.

Exploring Mailgun - Email Reputation Score Over Time

Real-time charting and reporting provide you a view of your email activities:

Exploring Mailgun - Charts of Organization Email Activity

Mailgun's managed email services help with all of the following needs:

  • Deliverability and recipient engagement management
  • IP allocation management
  • Managed IP warmup
  • Reputation monitoring and consulting
  • Sending infrastructure consulting
  • Email tracking and testing consulting
  • Custom reverse DNS on all your IPs
  • Dedicated IP subnets with bursting to high quality shared IPs

Sending High Volume Email

Many Mailgun customers use its APIs to automate their email needs. Mailgun offers a high-performing automated email engine with first-class reliability.

When you log in to the Mailgun control panel, you'll be greeted with a chart of recent activity for all of your domains:

Exploring Mailgun - Mailgun control panel activity charts

Using the Mailgun API

When you use the Mailgun API, you'll have full control over every aspect of your emails.

Recipient variables allow you to easily personalize all your emails for each user. First name, order value, and other common fields are easy. And you can personalize the entire look of the email by including image URLs with your recipient variables.

You don’t have to come to Mailgun to find out what’s happening to your email. They find you. Using webhooks, you can receive real-time notifications for everything that is going on with your email.

As your recipients interact with their email, their activities trigger webhooks, which Mailgun can then use to notify your app directly:

Exploring Mailgun - Webhook activity flow

Here's a Mailgun hangout that talks about Webhooks in more detail:

Mailgun's extensive logs help you track and debug any issues that might come up:

Exploring Mailgun - Logs

Using SMTP

You can also use Mailgun as an SMTP delivery engine. While the Mailgun API offers better long-term performance and maintenance, SMTP is an open and established protocol with a large ecosystem that will work with many established systems and applications.

Exploring Mailgun - SMTP Activity Flow

For example, many WordPress publishers lack outbound email services on their hosting plans and struggle to set up basic contact forms for their website. The free Mailgun Plugin for WordPress solves this problem by powering outbound WordPress email with Mailgun's SMTP interface. It's also more secure than operating your own SMTP service, which is filled with risks.

Installing the Mailgun for WordPress plugin is easy:

Mailgun WordPress Plugin - Search for the Mailgun Plugin to Install Now

Once installed, you can also use widgets or shortcodes to collect subscriber emails for your website. It also can support gathering subscriptions to multiple lists.

Mailgun WordPress Plugin - Adding a Subscription Widget

HTML Email Templates

Sending emails programmatically requires extensive expertise in building HTML templates with compatibility across clients and email services. It's time-consuming. Mailgun's begun offering a small suite of pre-built, tested email templates which they share with you. Here's an example invoice:

Exploring Mailgun - Example HTML Template of an Invoice

Here are links to the existing HTML templates which you can reuse or build on for your application:

Mailgun's tested these on a variety of email clients and services:

Exploring Mailgun - Services that Mailgun HTML templates are tested on

The templates are downloadable from their open-source GitHub account.

Excellent Developer and API Documentation

As a developer, Mailgun has top-notch documentation. It provides support for a variety of languages, e.g. Ruby, Python, PHP, Java, C# and Go. It provides working examples of implementing Mailgun functionality across its services, whether you're broadcasting, tracking or routing.

Exploring Mailgun - API Reference and Documentation


Exploring Mailgun - Jonathan Novak Uservoice Email Parsing Testimonial

You can configure Mailgun to receive all your inbound mail, process it and route it to other email addresses or web applications. The front-end user interface for configuring routing is friendly and easy to use:

Exploring Mailgun - Routes in the Control Panel

Essentially, Mailgun takes unstructured inbound email (shown at left) and sends your application parsed, structured data (shown at right):

Exploring Mailgun - Email Parsing Example

Developers spend months coding email parsing on their own, a task that's never really complete. Mailgun manages this for you.

Exploring Mailgun - Parsing and Routing Activity Model

Mailgun's routing features also provide the following capabilities:

  • Optionally receive raw MIME message
  • All messages encoded to UTF-8 automatically
  • Free spam filtering
  • Easy testing of webhook endpoints
  • Text-part generation from HTML-only emails
  • Matching on all email headers (e.g. subject, from:, cc:) and recipients
  • Ability to chain together multiple filters to provide sophisticated expressions

Campaign Tracking and Analytics

Mailgun supports campaign-ids in your email and can track performance of any of your broadcast efforts by these ids.

Furthermore, regular analytics are provided through the web interface or through the Stats API:

Exploring Mailgun - Message Activity Charting and Tracking

You can also segment your emails using tags. With tags, you can create simple A/B tests or do deeper cohort analysis.

If you also use webhooks, your tags are automatically encoded into the webhook, which makes tying email back to your data a breeze.

With tags and webhooks, it becomes straightforward to gain the following analytical functionality:

  • Unsubscribe tracking
  • Open & Click tracking
  • Geolocation data on recipients
  • Email client and device tracking
  • Top performing links

Here are a few of Mailgun's client case studies showing its powerful tracking and analytics features at work:

Spam Filtering

As you use Mailgun to process your inbound mail, you can ask it to apply various levels of spam filtering:

Exploring Mailgun - Spam Filtering for a Domain

This can greatly reduce the processing load of your own application on the remaining, valid email.

Mailing Lists 

Mailgun also offers mailing lists which you can use for various purposes or campaigns. You can set them up through the control panel user interface or the Mailing List API:

Mailgun - The Mailgun Control Panel Lists Index

It's easy to create lists through the control panel:

Exploring Mailgun - Create a New Mailing List

You may also want to check out my Mailgun blog post about a third-party PHP-based application which uses various features of the mailing list API: Open-source mailing list applet using the Mailgun PHP SDK.

Email Validation

While RFC email standards state formal rules for email addresses, in the real world email service providers accept addresses that are not RFC-valid, and reject addresses that are.

Mailgun built its own email validator based on real-world data and the RFC specification to ensure more accurate validation. They provide access to the validator through its open-source JQuery Email Validator plugin.

You can try out Mailgun's email validation on its website and then integrate it into your application anywhere:

Exploring Mailgun - Email Validation JQuery Plugin Example

The Mailgun Plugin for WordPress

The Mailgun WordPress plugin enhancements that my company, Lookahead Consulting, built last year is the connection to the Mailing List services. The plugin makes it easy to gather WordPress subscribers into your Mailgun account:

Mailgun WordPress Plugin - WordPress Plugin Mailing Lists Index

In Closing

Mailgun offers a vast array of email services that are relevant to all kinds of coding, marketing and business development needs. And, impressively, they do a great job at all that they offer. Certainly this is a sponsored post, but as an experienced user, I offer my authentic recommendation for you to try out the service today. I hope you're excited to do so. 

Please let me know which Mailgun features you'd like to see more written about in the future. You can post them in the comments below or reach me directly on Twitter @reifman.

Related Links

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.