How to deep link to iOS Mail
No jailbreak necessary, enjoy it while it lasts!
Create deep links to emails in Mail on iOS 7+ with the following URL scheme:
where message-id is the URL-encoded value of the “Message-ID” header field in the email you want to deep link.
The only requirement is that the target email has been downloaded in Mail already. A happy by-product of this behavior is that you can use a dummy string for the message-id to just launch the Mail app generally (e.g. as a convenience to take a user to their inbox from your app signup flow).
I often create iOS Calendar events directly from emails in Mail. If you’re unfamiliar with this feature, Apple automagically detects date/time references in the body of an email and turns them into tappable links that then allow you to “Create Event” directly from the original email:
Starting in iOS 7, a Calendar event created this way automatically includes in the event details a link that reads “Show the message in Mail”. When tapped, it opens the original email directly in Mail:
This is pretty exciting stuff! Emails contain so much context for entities like events, tasks, contacts, and files. On iOS this context has long been trapped inside Mail, which lacks the programmatic access that’s available for other system apps like Contacts and Calendar. If Apple is now using app URLs to deep link to emails in Mail then maybe 3rd party apps can do the same?
To inspect the URL, I did a press-and-hold on the “Show the message in Mail” link to get the “Copy” action (which I half expected to be blocked by Apple here, but it was accessible) and then pasted it into plaintext:
Now all that was left was to figure out how this URL indexes into a specific email in Mail. Having spent more time hacking email client libraries than I’d like to remember, I noticed that the URL string to the right of the colon looked suspiciously like a URL-encoded email header.
I looked up the corresponding deep linked email in Gmail so I could view the raw email message and, sure enough, the URL-decoded string was a character-for-character match of the “Message-ID” field:
So the scheme for constructing deep links to emails in Mail.app is (simply):
For good measure, I did a quick check to make sure Apple didn’t restrict the use of Mail deep links to just the Calendar app. Constructing the deep link URL for a different email in my Inbox and manually opening it via Safari worked like a charm. I haven’t had a chance to build a test iOS app to open a Mail deep link programmatically but at this point I’m pretty sure it’ll work.
The only requirement for this to work as advertised is that the target email must be downloaded and available in Mail. The drawback, of course, is that there’s no way to know this for sure programmatically. For example, a user could at any point decide to delete the original email (though, as it turns out, a deep link to a now-deleted email still opens the email from the “Trash” folder in Mail!).
A happy by-product of this URL scheme and behavior is that you can use a dummy string for the message-id to just launch the Mail app without deep linking to a specific email. This can enable scenarios where an app may want to launch the user directly into their inbox e.g. to verify their email address to complete the signup process.
To this day, iOS Mail remains a blackbox to iOS designers and developers, despite how central email and Mail is to so many mobile workflows and experiences. So it’s quite an exciting little discovery that it’s now technically possible to design a user flow that ties directly back to emails in Mail.
It’s unclear exactly how much mileage 3rd party apps and services can get out of this little hack alone. But if they can gracefully handle “false positive” cases and/or minimize their incidence altogether, they could tap into some immediately interesting scenarios.
Of course, all this assumes deep linking to Mail is even around to stay. The pessimist in me thinks Apple overlooked this deep link “loophole” in their rush to get iOS 7 out the door and they’ll close it in a future iOS update. The optimist in me holds out hope that Apple will surprise us with richer APIs and access to Mail so we can introduce this new dimension to iOS experiences (which is ultimately to Apple’s own benefit).
Here’s to a glass half full.