• What's new

The Official Go SDK, Available Now

Mailgun Team
5 min read

Today, we’re happy to announce the general availability of our Mailgun-Go SDK. Now you can send messages through Mailgun using Go! Mailgun-Go allows you to easily interact with our API by greatly reducing the amount of boiler-plate code you need to maintain.

Our SDK is built from a simple foundation graciously offered by Michael Banzon on Github. We are truly indebted to him for his support. We added features on top of his own SDK, including significantly enhanced API coverage, and a rich set of acceptance tests to help developers get started and better understand how to use the SDK.

Mailgun-Go lets you send messages to mailing lists of arbitrary size, subject only to the limitations of your Mailgun account. Here’s a simple example where we send one message to three recipients:

1mg := mailgun.NewMailgun("example.com", "key-example", "")
3m := mg.NewMessage(
4 "Dwight Schrute <dwight@example.com>", // From
5 "The Printer Caught Fire", // Subject
6 "We have a problem.", // Plain-text body
7 "Michael Scott <michael@example.com>", // Recipients (vararg list)
8 "George Schrute <george@example.com>",
9 "it-support@example.com",
12_, _, err := mg.Send(m)
14if err != nil {
15 log.Fatal(err)

and here’s one where we send the same message to potentially millions of recipients:

1mg := mailgun.NewMailgun("example.com", "key-example", "")
3m := mg.NewMessage(
4 "Dwight Schrute <dwight@example.com>", // From
5 "Help!", // Subject
6 "The printer's on fire on floor %recipient.floor%!!" // Plain-text body
9// Iterate over a collection of addresses and per-user variables.
10for _, user := range mailingList {
11 err := m.AddRecipientAndVariables(user.address, map[string]interface{}{
12 "floor": user.floor,
13 })
14 if err != nil {
15 log.Fatal(err)
16 }
19_, _, err = mg.Send(m)
21if err != nil {
22 log.Fatal(err)

As you can see, the Mailgun-Go SDK provides an interface that scales pleasantly with your needs.

We will be updating our online documentation to include Go examples soon. In the meantime, please feel free to consult our documentation on GoDoc, read the acceptance tests in our Github repository, or open a new issue through Github or your control panel. We’ll be happy to answer any questions you have!

Happy Sending!


Learn about our Deliverability Services

Looking to send a high volume of emails? Our email experts can supercharge your email performance. See how we've helped companies like Lyft, Shopify, Github increase their email delivery rates to an average of 97%.

Learn More

Last updated on August 28, 2020

  • Related posts
  • Recent posts
  • Top posts
View all

Always be in the know and grab free email resources!

No spam, ever. Only musings and writings from the Mailgun team.

By sending this form, I agree that Mailgun may contact me and process my data in accordance with its Privacy Policy.

sign up
It's easy to get started. And it's free.
See what you can accomplish with the world's best email delivery platform.
Sign up for Free