The Mailgun API is built on HTTP. Our API is RESTful and it:
Because of this there is no need for developers to learn yet another 3rd party library to use the API. You can use your favorite 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 langauges by using the language bar at the top. Below are the language-specific notes we feel are useful.
Python users love Requests HTTP library. It is simple, elegant and yet very powerfull. To install it you could 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.
Note
Our code samples use Requests version 0.7.5. Later 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.
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
In case you want to send data with keys that have multiple values you will most likely need some kind of multimap. And we recommend gem called multimap. What a coincidence! To install it just type:
gem install multimap
Check out jersey REST client if Java is your weapon of choice. It took us 3 jars to get all we needed:
- jersey-client.jar
- jersey-core.jar
- jersey-multipart.jar
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
PHP users can use PECL extension pecl_http and cURL library.
Bellow are all the steps needed to install these libraries having a fresh Ubuntu installation.
Run:
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 enable pecl command:
sudo aptitude install php-pear
To install pecl_http module which we used for the ability to send several attachemts:
sudo pecl install pecl_http
If configuration option php_ini wasn’t set to php.ini location when you run this command you should add extension=http.so to your php.ini file.
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 libraries are installed, making HTTP requests becomes no more difficult then in any other language.