The Mailgun API is built on HTTP. Our API is RESTful› and it:

  • Uses predictable, resource-oriented URLs.
  • Uses built-in HTTP capabilities for passing parameters and authentication.
  • Responds with standard HTTP response codes to indicate errors.
  • Returns JSON .

Mailgun has published libraries for various languages. You may use our libraries, or your favorite/suggested HTTP/REST library available for your programming language, to make HTTP calls to Mailgun.

Most code samples in our docs can be viewed in several programming languages by using the language bar at the top. Below are the language-specific notes we feel are useful.


Standard HTTP Library:

Python users love Requests HTTP library. It is simple, elegant and yet very powerful. To install it you would simply run:

pip install requests

You may also need a MultiDict class to represent HTTP requests with multiple values per key. We recommend WebOb's MultiDict but Werkzeug/Flask also offer MultiDict class.


Our code samples use Requests version 0.7.5. Older versions of Requests don't take multi dictionaries. For post data and query params you could use lists to pass multi-valued keys. Unfortunately it won't work for files.


Standard HTTP Library:

Ruby folks recommend rest-client and not without a reason: it is one of the most beautiful REST HTTP libraries we have seen. The library is available as gem, so to install it simply run:

gem install rest-client

Official Mailgun Ruby Gem:

This is the Mailgun Ruby Library. This library contains methods for easily interacting with the Mailgun API. Fork it on GitHub or read more about the gem here.

gem install mailgun-ruby


HTTP libraries:

Use your favourite HTTP library like Mojo::UserAgent, Furl or LWP::UserAgent.

API libraries:

Mojolicious Plugin:

Email::Sender Transport Module:


Standard HTTP Library:

Check out the UniRest REST client if Java is your weapon of choice.

You will also need the following dependencies -

(org.json, httpclient 4.3.6, httpmime 4.3.6, httpasyncclient 4.0.2)

Kotlin ====

Kotlin users could of course use the Java library, but for an alternative, take a look at this library:



Go developers can use the standard net.http library or the mailgun-go library to interact with the mailgun api.

If you are using mailgun-go and golang modules from go 1.11 make sure you include the /v3 at the end of your import paths.

$ go get

If you are not using golang modules, you can drop the /v4 at the end of the import path. As long as you are using the latest 1.10 or 1.11 golang release, import paths that end in /v4 in your code should work fine even if you do not have golang modules enabled for your project.

$ go get


Standard HTTP Library:

For C# developers there is RestSharp. And that's it, nothing else is required. Standard .NET makes it easy to make HTTP requests.

However, if you are using mono you will most likely need to allow it to do HTTP requests to external sites first. The easiest way to do that is probably by installing Mozilla certificates, like so:

mozroots --import --sync


Mailgun Library:

Our PHP library is robust and provides an excellent interface to easily interact with our API.

GitHub Repository: mailgun-php

Minimum PHP Version: 5.5.0

To install the library, you will need to be using Composer in your project. If you aren't using Composer yet, it's really simple! Here's how to install composer and the Mailgun library.

# Install Composer
curl -sS | php

# Add Mailgun and Guzzle6 as a dependency (see GitHub README below for more info)
php composer.phar require mailgun/mailgun-php php-http/guzzle6-adapter php-http/message

Next, just include Composer's autoloader in your application to automatically load the Mailgun library in your project.

require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mailgun = Mailgun::create('key-example');

For additional information, see the GitHub Repository README file.

Standard HTTP Library:

PHP users can use PHP cURL library.

Below are all the steps needed to install this library from a fresh Ubuntu installation.


sudo aptitude install libmagic-dev
sudo aptitude install php5-dev

Then to enable curl support:

sudo aptitude install libcurl3

Then if you plan to run scripts from CLI:

sudo aptitude install php5-cli

To install cURL for php which we used for the ability to send put data:

sudo aptitude install php5-curl

That should be all. Quite a list, isn't it? But firstly, we had only a fresh Ubuntu installation when we started and secondly, once the library is installed, making HTTP requests becomes no more difficult than in any other language.


Check out the available node modules from the community.

We also have a step by step tutorial post on sending email with Node.js.


Lua and luvit users have two easy options. Either the luvit-curl library or the luvit-request library.

Due to luvits asynchronous i/o nature, code samples from node.js can be easily retrofitted to work in luvit with luvit libraries.


curl is a popular command line tool to send HTTP requests. It is very simple and yet quite powerful. With it you could send data using any HTTP method. You could send post data and query params and files in a very consistent and elegant way. An excellent choice to study the API.