Tracking Replies in Mailgun (or any other email service)

Written by Mailgun Team

Categories: Email DIY

1 minute read time

We’ve recently been inundated with questions about how to track which email a recipient has replied to. There are many use cases for needing to do this. You may want to thread a conversation in your App or you may want to measure engagement. The problem with relying on Mailgun Tags or Campaign-IDs is that these are not standard MIME headers so the receiving email service provider (ESP) may strip them out.

The proper way to do this is to use the Message-ID header because when a recipient replies to an email the Message-ID of the original email is included in the In-Reply-To header of the reply.

Let’s walk through an example.

When you send an email using Mailgun, Mailgun automatically creates a Message-ID and includes it in the response (you could also set your own custom Message-ID).

So if I send a message using the messages API:

curl -s -k --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 
 -F from='Excited User <>' 
 -F to='test <>'
 -F subject='Hello' 
 -F text='Testing some Mailgun awesomness!'

Mailgun replies with:

"message": "Queued. Thank you.",  
 "id": "<>"

You can see it in a screen shot of my terminal:

Terminal screen

Now when I open that email in an email client and look at the email source headers, you can see that Message ID:

Email Headers

Ok, now let’s see what happens when I reply to that email. I created a Route in Mailgun that posts my reply to a URL at Postbin. Of course, Mailgun dutifully posts all of the headers. As you can see below, the In-Reply-To header has the same Message-ID which you then can use to identify which specific email was replied to:

Specific email that was replied to

So that’s it, an easy way to track who’s replying to what.

Happy emailing!


Modified on: March 13, 2019

Stay up-to-date with our blog & new email resources

We'll let you know when we add new email resources and blog posts. We promise not to spam you.