Mail Message Showing Message ID

Why Would You Want to Create a Deep Link to an Email?

I’m not one of those highly organized, Getting Things Done people with OmniFocus tasks and due dates that I actually achieve. I use a hodgepodge of techniques that seem to revolve around my email. I know, that made many of you cringe, but I’ve got a cool trick that is starting to help me connect relevant emails to my tasks.

The Problem to be Solved

Let’s start with a pretty simple example. We all order a lot of stuff online these days. I find myself losing track of what I’ve ordered, when I’ve ordered it, where I ordered something from, when I was supposed to get it, and forget all about knowing my order number.

About a year ago I started a list that called “Ordered Items” in Microsoft To Do (the love child of Wunderlist). When I order something, I create a new item in To Do. Every item in To Do can have steps within it, reminders, due dates, file attachments, and free-form notes.

So let’s say I order some IKEA shelves. I create an item in To Do and then go to the email confirmation and copy the information out of it, like the order number and delivery date so if it never shows up I can check up on it. Often I need more detail from the email at a later date, and I’d have to hunt through my 70,852 saved emails to find it.

Deep Linking

I’ve found a better solution for this, and it’s pretty nerdy which makes me like it even better. It’s called deep linking. I don’t remember how I discovered the concept but I learned the super nerdy details about deep linking from a blog post at nshipster.com/….

The main thing you need to know is that every email message you receive has a unique message-id associated with it. Given that unique message-id and a bit of reformatting, we can create a link to plop in anywhere that when clicked will launch the email in Mail.app.

Revealing the Message-ID

The first thing we need to do is to tell Mail that we want to be able to see the message-ID header when viewing our emails. We only have to do this once.

To reveal the message-ids on your emails, open up Mail’s preferences, and select the Viewing tab. You’ll find an option to Show message headers with a dropdown next to it which probably says Default. Select Custom from the dropdown, and then in the little window that comes up, tap the plus button and then type “Message-ID” and select OK, and close Mail Preferences.

Mail Preferences Show Message ID
Mail Preferences Show Message ID
Mail Preferences Add Message ID
Mail Preferences Add Message ID

Now when you look at your email messages, along with who they’re from, the subject, and who the message was to, you’ll see a long, gloppy-looking message-ID:

<[email protected]>

Mail Message Showing Message ID

The format of the message-ID is interesting. It’s enclosed in angle brackets, it starts with a lot of numerical digits separated by dots, it’s got an @ symbol in the middle, and it ends with the domain that sent it, such as ikea.com. This unique identifier is what we’ll be using to link to an email, and luckily we don’t need to understand much about it to use it.

Reformatting the Message-ID

While this message-ID has the information we need, in order to actually use this crazy looking message-ID, we need to reformat it a bit to make it a deep link.

You know how web URLs start with https://? The format of a deep link starts with message://. So far that’s not too scary. The next part is a little weirder. Certain symbols can’t be understood by computers, so we have what are called ASCII codes for non-printable characters. The reason I bring up this arcane topic is that we need to replace the angle brackets in our message-ID with their ASCII codes for them to be recognized in the deep link. The left angle bracket (the one that looks like a less-than symbol) will be replaced with %3c and the right angle bracket (greater than symbol) will be replaced with %3e.

So now our final format for the deep link is:

message://%3c[email protected]%3e

I wonder how many people stopped listening when I got to the ASCII code for non-printable characters? If you’re still with me, hang in there because you’re not going to have to do any of this by hand.

TextExpander to the Rescue

TextExpander Snippet for Deep Link
TextExpander Snippet for Deep Link

I played with this a bit and realized that I was never going to remember the ASCII codes and the formatting of message://, so I turned to one of my favorite tools for help, TextExpander.

TextExpander at its most basic will spit out a snippet of text when you type the abbreviation you assigned for it, but it can do a lot more than that. One of the things it can do is embed your clipboard in the snippet it spits out, and we’ll use that feature to create our deep link automatically.

TextExpander Keyboard Macro for Clipboard
Insert Clipboard in TextExpander Snippet

In TextExpander I simply typed in message://%3c , then clicked the little keyboard symbol to bring up keyboard macros, and selected Clipboard, then followed that with %3e.

I’ve managed to make that sound super complicated, but it took maybe 30 seconds to accomplish. I chose the letters msg; to trigger my snippet of text and I was ready to go.

Usage

Deep Link in To Do
Deep Link in To Do

All of the heavy lifting is over now. To use my fancy new TextExpander snippet to deep link to an email, the process is simple. In the email to which I want to link, I copy the message-ID without the angle brackets. I switch to wherever I need to put the deep link, in my example this would be in my To Do List. I type my abbreviation, and the deep link splats into the open text field. It’s ugly as sin (as my father would say), but it’s a real link and when I click it, Mail launches directly to the order email from IKEA. Mission accomplished and all I need to remember is my TextExpander abbreviation.

Remember that this whole thing doesn’t have anything to do with Microsoft To Do, that’s just one of the places I use it. I got an email from someone telling me they wanted to meet and included a lot of important information in the email. I copied the Message-ID from the email and then used my TextExpander abbreviation to paste it as a deep link into a Calendar event. Unlike To Do, when you use this in Apple’s Calendar app, it converts the gloppy message:// etc into “Show in Mail…” which looks great and is much less confusing.

Deep Link In Calendar Event
Deep Link In Calendar Event

Now that I have this working, I’m finding lots of places where it’s handy to drop in a link to an email so I can connect information together and not have to go hunting for it later.

I use this trick often but not quite often enough to remember whether or not I’m supposed to copy the angle brackets. I’m not sure why this works, but if you do copy the angle brackets, they just get ignored and the deep link still works!

Can’t Keyboard Maestro Do This?

Deep Link Conversion in Keyboard Maestro
Deep Link Conversion in Keyboard Maestro

At least some of you are yelling into your devices that I could have used Keyboard Maestro for this instead of TextExpander, and you’d be absolutely correct. I’m not as good at Keyboard Maestro yet as I am with TextExpander, but I got it to work. Remember we start with the message-ID copied into the clipboard, so the steps I put into Keyboard Maestro are:

  1. Set variable messageID to the system clipboard
  2. Prepend the variable messageID with message://%3c
  3. Append the variable messageID with %3e
  4. Set the system clipboard to the variable MessageID
  5. Paste

Just to keep it as much like the TextExpander snippet as possible, I set the Keyboard Maestro trigger to be a text string and in this case, I chose mid;. Keyboard Maestro doesn’t work quite the same as TextExpander so after I typed the trigger and it pasted in my newly-formed deep link, the trigger text string was still there. Luckily Keyboard Maestro offered to simulate deleting the characters of the trigger before executing which made my macro work properly.

Now I can select the message-ID from Mail, type my text string and the deep link is pasted wherever I want it.

I bet there’s a more elegant way to write the macro in Keyboard Maestro and I’m sure Mike Price will write an improved version when he hears how I did it. It will be awesome and filled with funny comments too. But my method does work so I’m happy.

Bottom Line

I’m sure at least 90% of you think I’m nuts that this is a time-saver, and too nerdy for you, but I use this pretty often and I love the efficiency of it. Now that I’ve spoon-fed it to you with screenshots using two different tools, why not give it a try? The worst thing that can happen is that you love it.

14 thoughts on “Why Would You Want to Create a Deep Link to an Email?

  1. Kyle - August 26, 2021

    Alison, is this the sort of thing that Hook https://hookproductivity.com/ can do?

  2. Allison Sheridan - August 26, 2021

    I don’t know, Kyle. I did take a look at Hook a while ago but all I remember is that it didn’t tickle me enough to use it.

  3. Tim McCoy - August 27, 2021

    Al, I don’t use textexpander or keyboard maestro – I liked the idea of this task – so I was writing an automator script to accept a Message-ID text and modify it accordingly. It works really well. I also create a calendar new event (little problem though, later…) that I could paste the message URL in to – easy enough, but when I click Calendar URL Mail tells me it can’t open the mail because the Mac has converted your ‘%3c’s to ‘%3C’. The Message-ID I pasted into the calendar IS correct though.

    Example:
    message://%3c6Uk.406749.80358.198192.1630090949.7581623.1HOt@a2plmmsworker01.prod.iad2.gdg.mail%3c

    The operation couldn’t be
    completed. (MCMailErrorDomain
    error 1030.)
    Mail was unable to open the URL
    “message://
    %3C6Uk.406749.80358.198192.163009
    0949.7581623.1HOt@a2plmmsworker01.
    prod.iad2.gdg.mail%3C”

    Any ideas?

    P.S. ‘the little problem’ is that the Automator’s “New Calendar Event” has a fixed date for execution, that once run, is the default and it ends up in some future or past location on the calendar; it never starts on “today” as I think it should.

  4. Allison Sheridan - August 27, 2021

    Without seeing (and understanding) the script, I don’t think I can analyze it. I guess you have to figure out what’s changing the %3c into %3C, don’t you? I am just copying, running the script and then pasting into existing emails, calendar events and to do lists, not trying to auto-generate an email. Can you convert your script to just let you paste after it runs so it’s generic to be useful across apps?

  5. Tim McCoy - August 27, 2021

    To share with other readers…
    Good idea not relying on Automator to create the bad date event. I disabled that functionality (but left opening the calendar) and created the event a designated day, and add the URL to “URL” closed the event. Later opened the event but it made the same error. i.e.; %3c to %3C . Hmmm do you still work properly?

    Pasted: “message://%[email protected]%3c”

    Response in mail from click in calendar:
    The operation couldn’t be
    completed. (MCMailErrorDomain
    error 1030.)
    Mail was unable to open the URL
    “message://message://
    %3C8DWszUIVNnAFgAQUGFU0cWfmTz
    [email protected]
    m%3C”.

    System:
    macOS Big Sur
    Version 11.5.2
    iMac (Retina 5K, 27-inch, Late 2014)
    Processor 4 GHz Quad-Core Intel Core i7
    Memory 32 GB 1600 MHz DDR3

  6. Tim McCoy - August 28, 2021

    Al, You didn’t catch in my code – and I missed it in your explanation – I was ending the modified URL with %3c, NOT %3e .
    problem with URL resolved in calendar. Now to get current date as a default in an automated calendar entry…

    Thanks Allison.

  7. Allison Sheridan - August 29, 2021

    Want to know why I didn’t catch it in your code, Tim? Because you never showed us your code (and I asked you to post it!) Glad you were able to find your mistake.

  8. Tim McCoy - August 29, 2021

    You are right, I should not have said “code”, just above. I should have referred you to “Pasted” , further above, where I showed what I pasted.

    Now working on not requiring any pasting at all – get everything from the mail…

    Thanks Allison,

    BTW how do you post an automator script – just asking.

  9. Allison - August 29, 2021

    I suppose you could put it in dropbox and put a link in the comments?

  10. Tim McCoy - August 29, 2021

    Okay Al, My first foray into applescripting. Taking your idea about puting a mail message: URL into a calendar entry. This preliminary version continues to leave pasting up to the user, but it collects the message-ID automatically from the selected email and puts it into the clipboard to be used wherever you want it to be. Last it creates a Calendar entry event 7 days in the future (my default, which of course can be changed easily) and opens the calendar. The entry name is derived from the ‘reply to’ text of the email. Finally, currently, you have to find the new calendar event and paste the message-id from the clipboard into the add URL of the event.

    TODO: make it automatically fill the message URL field, and set an alarm in the calendar for the event.

    I run this applescript in an automator application called packages.app which currently resides on my desktop but will likely change to a mail service when complete.

    FWIW:

    #———————————————————-
    on run {input, parameters}
    global newreplyto
    set theStartDate to (current date) + (7 * days) # will create event 7 days from now
    set hours of theStartDate to 8
    set minutes of theStartDate to 0
    set seconds of theStartDate to 0
    set theEndDate to theStartDate

    tell application “Mail”
    activate
    set msg to “Select a Mail message to copy its Message ID”
    display dialog msg buttons {“Cancel”, “Selected”} default button 1
    end tell

    if button returned of result is “Selected” then
    tell application “Mail”
    set theSelectedMessages to selection
    set the selectedMessage to item 1 ¬
    of the theSelectedMessages
    set messageID to the message id of the selectedMessage
    set replyto to the reply to of the selectedMessage
    set AppleScript’s text item delimiters to {“@”}
    get last text item of replyto
    set newreplyto to result
    set the clipboard to “message://”
    end tell
    set AppleScript’s text item delimiters to {“,”}
    tell application “Calendar”
    activate
    tell calendar “Tim”
    make new event with properties {summary:”Package due ” & newreplyto & “:”, start date:theStartDate, end date:theEndDate}

    end tell
    end tell
    end if
    end run
    #———————————————————-

  11. podfeet - August 29, 2021

    Looks like you’re having a lot of fun with this, Tim! I’m not sure I would have advised learning AppleScript & Automator at this time, as it Apple appears poised to replace it with Shortcuts. I don’t know if it will be sunsetted any time soon but it doesn’t smell like it’s long for this world. It IS cool that AppleScript can pull the message-ID without you having to copy it.

    I’m curious why you like having this so structured that it can only make a calendar invite and the title is specified and all that? My solution was to be as generic as possible so I can drop links into any applications from Mail.

  12. Tim McCoy - August 29, 2021

    Title was specified because different delivery vendors (Amazon, Costco, HomeDepot etc) – need to differentiate. The clipboard retains the message info to paste wherever you like.

  13. Tim McCoy - August 29, 2021

    Forgot to mention that, if anyone wants to use this, you would need to change my “Tim” to a calendar named in your calendar.

    BTW, Al, shortcuts are only for IOS I believe (at this time, there may come a time.)

  14. paul - August 30, 2021

    thank you for this
    I can now set reminders for emails I receive

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top