Product
Originally posted on December 7, 2013.
This week, in addition to writing about what we learned open sourcing a major part of Mailgun, we released a new feature we think you’ll appreciate: a postbin for debugging your webhooks.
We try not to suffer too much from not-invented-here syndrome at Mailgun (we’re engineers though, so it’s hard) and for years, there were a couple Postbin’s that we used regularly, and encouraged our customers to use, for debugging webhooks. Our favorite was postbin.ryanbigg.com because it was simple, and the POSTs were easy-to-read. But it’s no longer available, and another that we liked was recently redesigned making it harder to use. So we decided to make our own, focusing on usability and simplicity.
If you go to http://bin.mailgun.net, you’ll now have the ability to create Postbin’s that allow you to easily debug your webhooks, Mailgun-related or otherwise.
Remember, since Mailgun let’s you test all your webhooks with a sample POST, you can enter your PostBin url in the Mailgun control panel and receive your test POST before coding anything.
In addition, the Mailgun PHP SDK has been modified to allow the Postbin as a destination, making it easy to see exactly what the SDK is posting to Mailgun’s API. Head over to the PHP SDK “Debugging” section for details.
Overtime, we’re hoping to integrate the Mailgun Postbin directly into your control panel, so that you can test your webhooks to a private postbin without having to enter a URL. Until that time, keep the following caveats in mind:
For developers who wish to provision a Postbin programatically, an API is available for the Postbin. Here are the available endpoints:
POST http://bin.mailgun.net/api/new
Creates a new Postbin
Response:
{
"url": "http://bin.mailgun.net/b50299cc"
}
POST http://bin.mailgun.net/api/<id>
Stores data in the Postbin
Response:
{
"message": "Post received. Thanks!"
}
DELETE http://bin.mailgun.net/api/<id>
Deletes a Postbin
Response:
{
"message": "Bin <id> deleted"
}
GET http://bin.mailgun.net/api/<id>
Retrieves the Postbin data
Response:
[
{
"id": 153,
"params": "{"recipient":"test@example.com","sender":"travis@example.com","stripped-text":"A POST!","timestamp":"1358041467"}",
"created_at": 1385798101,
"bin_id": 59
}
]
Once you’re finally ready to accept POSTs for real, you can use or modify this flask app to accept your POSTs:
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route('/mailgun-tracking', methods=['GET', 'POST'])
def tracking():
# access some of the email parsed values:
request.form['recipient']
request.form['from']
request.form['subject']
# extended parameters
request.form['Message-Id']
request.form['message-headers']
request.form['timestamp']
request.form['body-plain']
request.form['stripped-html']
request.form['stripped-text']
request.form['stripped-signature']
return "Ok"
if __name__ == '__main__':
app.run(host='50.56.174.200', port=100, debug=True)
Till next week.
Happy sending!
The Mailgunners