Skip to main content
mailers.io

Providers

Connecting Mailgun: domain, region and key

By mailers.io team Published 5 min read

Mailgun is one of the eleven sending providers you can connect to mailers.io. The connection is yours: mailers.io sends through your Mailgun account, Mailgun bills you, and the reputation of your domain stays with you. Mailgun has a few details that differ from the other providers, mostly around regions and domains, so this guide goes through them in order.

Before you start

You need:

  • a Mailgun account that is allowed to send;
  • an API key for the region your account uses;
  • a domain you can edit DNS for, ideally a subdomain used for sending. See the subdomain strategy;
  • room for the domain in your plan. Sending domains are limited per plan, so look at pricing before you start.

The summary of what mailers.io does with Mailgun is on the Mailgun integration page. Below is the longer version, with the reasons.

Why the region matters first

Mailgun runs two entirely separate data centres, US and EU. They are not two views of one account. Each region has its own host and its own copy of your account, and a domain that exists in one does not exist in the other. mailers.io therefore asks for the region when you add the server, and it calls the matching host.

Pick the region in which your domain was created in Mailgun. If you pick the wrong one, the connection test may pass with a valid key while the domain step then fails to find your domain, or creates a second, empty one in the other region. If you use both regions, connect each as its own server and give them names that say which is which.

Step 1: take an API key

Take an API key from your Mailgun account for the region you will use. As with any provider, a key made for mailers.io alone is better than the key your application already uses. You can then rotate or revoke it without breaking anything else, and the Mailgun logs show clearly which traffic came from where.

Step 2: connect the server

Open Sending, then Servers, and add a server. Choose Mailgun and fill in:

  • A name you will recognise in logs and reports.
  • Region, US or EU.
  • API key.
  • Speed limit (optional). See step 5.

Run Test connection. A failure usually means a key from the other region, a key with a stray space, or a key that was revoked. The key is sealed before it is stored and it is write-only: you can replace it by editing the server, but it is never shown again.

mailers.io sends through the Mailgun API as raw MIME, so the message you see in a preview is the message that goes out. It does not use Mailgun templates, and it does not use Mailgun’s own mailing lists. The tracking of opens and clicks comes from mailers.io.

Step 3: add the sending domain and publish DKIM

Mailgun sends from a domain that exists in your account and is verified. In mailers.io, open Sending domains, add your domain and choose the Mailgun server.

mailers.io creates the domain in your Mailgun account through the API and shows the DNS records that Mailgun returned. The one that matters most for the signature is the DKIM record. Publish the records at your DNS host and use the verify button. DNS needs time to spread, so a record you added a minute ago may not be seen yet; try again later before you assume something is wrong.

Mailgun signs with the DKIM keys of that domain, and mailers.io does not sign the message a second time. For how DKIM, SPF and DMARC fit together, read SPF, DKIM and DMARC explained.

Step 4: events come per confirmed domain

Bounces and complaints must come back so that bad addresses stop receiving mail. For Mailgun, mailers.io uses webhooks, and it registers them per domain, once the domain is confirmed.

That order has a consequence you will notice: until the DNS records are verified and Mailgun confirms the domain, no webhook exists for it, and events for that domain will not arrive. Send nothing important until the domain is confirmed and the status shows it.

Every webhook call is checked with an HMAC-SHA256 signature, so a request that Mailgun did not sign is rejected. A hard bounce or a complaint puts the address on your suppression list, and it is not mailed again. A soft bounce counts toward the soft-bounce limit. Suppressed recipients are never charged a credit.

Step 5: pace the server under your Mailgun allowance

Your Mailgun plan has its own sending allowance. Put a speed limit on the server that sits just under it, per minute, per hour or per day. mailers.io then paces itself, and Mailgun does not need to refuse anything.

If you want separate limits for separate streams of mail, add a server per key. A transactional key and a marketing key can have different speeds and different caps. If Mailgun does answer with a rate-limit error, mailers.io treats the server as busy and steps aside, and the message goes to another server or waits. Routing by provider quota and speed limits explains the order. Every plan has failover and rotation across your own servers, by default round robin with 3 attempts.

Step 6: send a test and read the log

Send a message to an address you own and open the log. You should see one attempt on the Mailgun server and a delivery event once Mailgun reports it. When an attempt fails, the error class tells you where to look: authentication points at the key or the region, a refusal about the sender points at the domain, and a rate limit points at the allowance or at a speed limit set too high.

A new domain has no history. Start with a small volume and raise it on a schedule with warm-up instead of sending a full list on the first day.

What mailers.io does not do for Mailgun

It does not raise your Mailgun limits or lift a restriction on the account. It does not use Mailgun templates or lists. It does not move a domain from one region to the other. And it does not give you an IP pool: your mail leaves through your own Mailgun account.

If Mailgun is only one of your servers, which is the safer arrangement, see why a single provider is a single point of failure.

Questions and answers

Which Mailgun regions are supported?

US and EU. They are separate data centres, each with its own copy of your account, so choose the one your domain was created in.

Are Mailgun templates used?

No. mailers.io renders the message from its own templates and sends it as raw MIME, so Mailgun templates are not involved.

How do I keep two Mailgun accounts apart?

Add each key as its own server. Limits and speed caps are set per server.

Do I have to add the domain by hand in Mailgun?

No. mailers.io creates the domain in your Mailgun account and shows the DNS records. You publish them at your DNS host.

Written by the mailers.io team. Published .

Keep reading

Related posts

Send cold e-mail from your own servers.

Connect your servers, import a list and write the steps. Replies stop the sequence.

  • 7-day money-back guarantee
  • Bring your own providers
  • Cancel anytime