Product
Recently, we began to receive a lot of requests from customers to have access to the content of their messages.
Internally, we store messages for 3 days for scheduled sends, troubleshooting and compliance verification. We’re happy to announce that we have exposed this feature in our events API!
You can see the API URL to the message along with its unique key under the “storage” section when expanding the log entry: 

To view the message in the browser just copy the URL and enter “api” as username and your API key in the password box. This will let you view the parsed message:

Sometimes it’s handy to analyze the raw MIME and maybe render it in your favorite email client. Not a problem, here is an example on how you can do that with Thunderbird and a little bit of python magic
# View a message using it’s Mailgun storage key.rnimport os rnimport sys rnimport requests rnrnif len(sys.argv) != 2: rn print u0022Usage: retrieve.py message_keyu0022 rn sys.exit(1) rnrn# keep it in secret! rnapi_key = u0022key-....u0022 rnrn# output file nameu2028rnfile_name = u0022message.emlu0022 rnrn# let's make the url for retrieval rndomain = u0022mailgun.comu0022 rnkey = sys.argv[1] rnurl = u0022https://api.mailgun.net/v3/domains/%s/messages/%su0022 rnurl = url % (domain, key) rnrn# this will help us to get the raw MIME rnheaders = {u0022Acceptu0022: u0022message/rfc2822u0022} rnrn# let's make a request to the API rnr = requests.get(url, auth=(u0022apiu0022, api_key), headers=headers) rnrnif r.status_code == 200: rn # dump the body to a file rn with open(file_name, u0022wu0022) as message: rn message.write(r.json()[u0022body-mimeu0022]) rn # open it in the bird rn os.system(u0022thunderbird -file %su0022 % file_name) rnelse: rn print u0022Oops! Something went wrong: %su0022 % r.content
When you run the script with the storage key as a parameter it will retrieve the message from Mailgun; save it to “message.eml” and open it in Thunderbird.

While we’re here we want to remind you that we made some improvements to our logs allowing you to view individual message history.
Happy message viewing!