Is it possible to "deep link" to a specific email in mail.app on Mac OS X?

For example, in a note-taking application like Evernote or an outliner, is it possible to create a link that will open a specific email in a specific folder in Mail.app on Max OS X?


Solution 1:

In OS X, you can use a URL of the format message:<MESSAGE-ID> to open the specific message in Mail.app. So how do we find the message ID? If the message includes a date or other "data detector", you can click the dotted line around that and add it to your calendar. Then in Calendar.app, the newly created event will have a URL, which you can copy.

A more convenient way is to use AppleScript. Run the following code when you have the message selected in Mail. This will copy the URL to your clipboard. There are various ways to set this up to run with a keyboard shortcut, etc.

tell application "Mail"
    set _sel to get selection
    set _links to {}
    repeat with _msg in _sel
        set _messageURL to "message://%3c" & _msg's message id & "%3e"
        set end of _links to _messageURL
    end repeat
    set AppleScript's text item delimiters to return
    set the clipboard to (_links as string)
end tell

Note the angle brackets in this script are written as the URL encoded %3c.

Source: https://daringfireball.net/2007/12/message_urls_leopard_mail