Mailgun Sandbox Domain Explained

It’s perfectly natural to send some test emails before reaching out to real users. If you don’t have to send them from your actual domain – that’s even better. That’s precisely what you can do with Mailgun sandbox.

How does it work? Is it sufficient for email testing purposes? Let’s see.

How does Mailgun Sandbox work?

Each Mailgun account comes with an individual sandbox domain at no additional cost. When testing email sending from Mailgun, you can use this domain instead of your actual business domain. As a result, the reputation of your real domain won’t be affected in any way.

To get started, create a Mailgun account if you don’t have one already and activate it. Then, open your individual dashboard and in the menu to the left pick Sending -> Domains. You’ll see here the list of configured domains + a sandbox domain assigned to your account. In our case, it’s the only one that made it to this list.

Click on the Mailgun Sandbox domain to see its settings. 

With sandbox domains, you can only send emails to up to five authorized recipients. Even if you’re using a test mode (more on this below) and not delivering any emails, you’ll need to get the authorization from each individual recipient.

To do so, type in their email address and they’ll immediately receive a verification email.

Once approved, the status will update on the list. Unverified recipients will remain, well, “unverified”.

Once you have this sorted out, pick the method for sending emails from your sandbox domain – API or SMTP – and follow the integration instructions.

Here’s a sample email you could send to test if everything works as expected:

curl -s --user 'api:YOUR_API_KEY' \
    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
    -F from='Excited User <mailgun@YOUR_DOMAIN_NAME>' \
    -F to=bill@gates.com \
    -F to=warren@buffet.com \
    -F subject='Hello, it’s me' \
    -F text='Got some money to spare? Looking for an investor.'

Of course, insert your API key and your sandbox domain into the respective fields and send the request. If you receive the following response, you’re all good:

{
  "message": "Queued. Thank you.",
  "id": "<20111114174239.25659.5817@samples.mailgun.org>"
}

In case you receive ‘Domain not found’, double-check that you have copied the correct sandbox domain. If the response is ‘Forbidden’, something’s wrong with your API key.

Since the emails should hit your recipients’ inboxes shortly, you’ll also be able to preview how they look. Naturally, you can format them freely with HTML and CSS and can also utilize MIME strings. See various examples in Mailgun Docs.

How else can you test emails in Mailgun?

Mailgun also has a number of other tools and features for email testing.

First of all, there’s a test mode. You activate it by simply adding ‘o:testmode’ as a parameter of your message and setting it to ‘true’. Example:

curl -s --user 'api:YOUR_API_KEY' \
    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
    -F from='Excited User <mailgun@YOUR_DOMAIN_NAME>' \
    -F to=elon@musk.com \
    -F subject='Hello, it's me' \
    -F text='Looking for an investor. Contact me'
    -F o:testmode='true'

Mailgun will accept this message (as long as the domain and API key are configured properly) but it will not send it to Elon. Note that testmode requests still use up your Mailgun credits.

Mailgun also features an email verification API. You can integrate it directly into your webforms and immediately catch typos in email addresses from popular providers, such as Gmail or Yahoo!. This way, you won’t send to mistyped addresses and won’t hurt your reputation this way.

Finally, Mailgun also features built-in tools for previewing emails. You can easily test your sequences and see how they would look on a wide range of devices and screen sizes.

Inspect & Debug Your Emails

Pros and Cons of Mailgun Sandbox

The sandbox domain clearly has some compelling advantages:

  • It’s available straightaway and very easy to use
  • It’s free of charge
  • Can be used via both API and SMTP
  • Sending from a sandbox domain doesn’t affect the reputation and, as a result, the deliverability

There’s also a number of cons:

  • You can only send to five (authorized) email addresses
  • You can’t inspect the emails sent this way in Mailgun
  • It’s not suitable for wider email testing

What to use if Mailgun Sandbox isn’t enough?

Mailgun sandbox domain is perfectly fine for testing a new integration or just trying out Mailgun as an ESP. But if you need a tool for email testing, the sandbox won’t do any good.

As we said before, there’s a number of other tools for email testing built into Mailgun. Validating email addresses will help you rule out several potential bounces. Previewing emails will eliminate various inconsistencies in design and will make your emails accessible to everyone. But to run more sophisticated, error-proof email testing, you’ll likely need more than that.

There are several ways to tackle this. You could set up dozens of fake emails for testing and send your test emails there. You could also mask the email addresses from your production database and use them for testing. But with either approach, you’re still hurting your deliverability and risking a random wave of test emails arriving in your users’ inboxes.

One would argue that the most error-proof approach is with a dedicated pre-production testing environment. Arguably the most popular tool in this industry is Mailtrap. Currently used by over 450,000 developers and QAs, it captures your test emails before they can be delivered to any recipients. You can then inspect each in dedicated inboxes.

You can review the code behind each email and quickly spot any errors. You can also assess the spam scores of your emails and set up rules for sharing test emails with your colleagues or clients. With the bcc feature, you can even monitor production emails and quickly react to any inconsistencies.