- What's new
Product Update: Message Timeline And Improvements To Event Logs
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
1# View a message using it’s Mailgun storage key.2import os 3import sys 4import requests 56if len(sys.argv) != 2: 7 print "Usage: retrieve.py message_key" 8 sys.exit(1) 910# keep it in secret! 11api_key = "key-...." 1213# output file name
14file_name = "message.eml" 1516# let's make the url for retrieval 17domain = "mailgun.com" 18key = sys.argv[1] 19url = "https://api.mailgun.net/v3/domains/%s/messages/%s" 20url = url % (domain, key) 2122# this will help us to get the raw MIME 23headers = {"Accept": "message/rfc2822"} 2425# let's make a request to the API 26r = requests.get(url, auth=("api", api_key), headers=headers) 2728if r.status_code == 200: 29 # dump the body to a file 30 with open(file_name, "w") as message: 31 message.write(r.json()["body-mime"]) 32 # open it in the bird 33 os.system("thunderbird -file %s" % file_name) 34else: 35 print "Oops! Something went wrong: %s" % 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!
Last updated on May 15, 2021
Product Update: Message Timeline And Improvements To Event Logs
Weekly Product Update: Support Center And Improvements To Domains And Events APIs
New Events API, Detailed Email Tracking And Search
Weekly Product Update: New Events API Available For Private Beta
Become an Email Pro With Our Templates API
How to Conduct a Comprehensive Email Deliverability Audit
Dark Mode for Email Survey: What Do Email Senders Think?
Email Accessibility Mistakes that Annoy Subscribers & How To Fix Them
What’s Cool About COIL
The Difference Between SMTP and API
InboxReady x Salesforce: The Key to a Stronger Email Deliverability
Become an Email Pro With Our Templates API
Google Postmaster Tools: Understanding Sender Reputation
Navigating Your Career as a Woman in Tech
Implementing Dmarc – A Step-by-Step Guide
Email Bounces: What To Do About Them
Announcing InboxReady: The deliverability suite you need to hit the inbox
Black History Month in Tech: 7 Visionaries Who Shaped The Future
How To Create a Successful Triggered Email Program
Designing HTML Email Templates For Transactional Emails
InboxReady x Salesforce: The Key to a Stronger Email Deliverability
Implementing Dmarc – A Step-by-Step Guide
Announcing InboxReady: The deliverability suite you need to hit the inbox
Designing HTML Email Templates For Transactional Emails
Email Security Best Practices: How To Keep Your Email Program Safe
Mailgun’s Active Defense Against Log4j
Email Blasts: The Dos And Many Don’ts Of Mass Email Sending
Email's Best of 2021
5 Ideas For Better Developer-Designer Collaboration
Mailgun Joins Sinch: The Future of Customer Communications Is Here
Always be in the know and grab free email resources!
By sending this form, I agree that Mailgun may contact me and process my data in accordance with its Privacy Policy.