Search code examples
mailgun

How to use Mailgun sandbox?


I am currently testing Mailgun. Therefore, I don't want to add any payment information at the moment.

So, I'm working with the sandbox, and a verified address in the authorized recipients attached to the sandbox. So far, following the documentation, this limited setup is supposed to be working for testing purpose.

I use Postman to better identify how to work with the API, excluding any potential issues with coding.

Here is my Hello World config:

POST https://api:[email protected]/v3/sandboxXXXXX.mailgun.org/messages

The dashboard indicates that the sandbox is located in the US, so I don't use the european API.

Body:

  • from: [email protected] (also tried the verified email address, and postmaster <postmaster@sandbox...>)
  • to: [email protected] (the verified email address)
  • subject: test
  • text: Hello World!

I get a 400 error, Bad Request, and the documentation suggests to look for missing parameters.

The other posts I found so far did not help me to find the error spot either.

Also, Mailgun provides a Postman collection. But it did not help either.

Indeed, I dream of a detailed information of the API requirements, value formating... What are the required parameters if the error means I miss some?

Any idea of what I am missing?


Solution

  • Here is the solution.

    I had to guess and analyze some examples from the provided Postman Collection to find out what the documentation is supposed to explain in the first place:

    4 Required headers:

    Authorization

    Value : Basic XXXXX, where XXXXX is the Base 64 encoded version of api:___your_API_key___.

    Content-Type

    Value : multipart/form-data; boundary=XXX, where XXX is any short single string that will be used to identify a boundary within the sent content.

    Content-Length

    Value : XXX, where XXX is the size of the body request.

    Host

    Value : mydomain.com, your IP if sending from Postman...