Universal Apple Mail message URL

I don’t know on which podcast I heard about it, although I suspect it was mentioned by John Vorhees (not certain), but I’m looking for the method to create a universal url for a message in Apple Mail such that, when this URL is added to any document (Notes, Agenda, Things, Fantastical, etc.), when tapped, it will take us directly to that message in Apple Mail.

Any help gratefully received.

1 Like

You can drag a Mail message on iPad into OmniFocus or Drafts and it will insert the message link in the resulting task or draft.

Just checked and it also works (with nicer looking results) in Notes.

1 Like

The harder way requires you to be able to view the full source of the email - see

Or do it on a Mac.

Thanks for this. I didn’t know you could drag a Mail message on iPad. I’ll check if it works for Agenda, etc.

The second method only works if there’s a date mentioned in the email - most mails to which I need to link don’t include dates in the body, just general info or attachments I need to reference.

I know a well-known member of the technorati worked out how to create a universal url that, I think, they turned into a shortcut.

I can’t remember if they discussed it on Mac Power Users podcast, App Stories or something else with Federico Viticci as one of the hosts.

I’ve tried a Google search but I don’t really have enough variables/know how to craft the search to pinpoint it.

No, if you read all the way the author discovered it by using a calendar URL but later shows how to get the message ID from the source. Still awkward though.

I’m not clear on how this works without the date in the email. Can someone elaborate?

View the full headers of the email. The link is then going to be message:// followed by the value of the Message-ID field.

I used the drag to OmniFocus feature to get the URL. But @MacSparky posted a great script you can use to get the URL from Apple Mail on your Mac. It works great with TextExpander. I use it regularly to put links to e-mail messages in Apple Notes.

AppleScript to Link to Apple Mail Messages

How do you view the full headers in iOS?

I use fastmail and the fastmail app allows you to view the full headers. It will depend on your email client - you can’t do it in Apple Mail. Even with fm it’s not at all convenient.

Thank you @iPersuade!

I believe this is exactly what I was looking for (although I thought it was a guest of Mac PowerUsers that mentioned it, not one of the hosts :sweat_smile:).

1 Like

Things’ email to Things feature is the only one of its kind that actually constructs a message: URL back to the initial email when you forward a message to your custom address. I didn’t think it was possible, but now that I know it is I wish Omnifocus (and IFTTT/Zapier for that matter) would build the same thing.

Thank you @iPersuade and of course @MacSparky for the great script to use with apple mail.
Since I’m not a TextExpander user, but was searching a solution for linking directly to mails a long time ago (I gave up until I saw your post and got motivated again).
Now I adapted the script to directly add all selected (not just the first) mail as links with their subject as title for the link to Drafts or Todoist. This works on the Mac with the URL schemes of the two apps.
If someone needs them here you go:

add selected mails to todoist:

tell application "Mail"
	set _msgs to selected messages of message viewer 0
	if (_msgs is not equal to missing value) then
		repeat with _msg in _msgs
			set _msgID to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & (message id of _msg)
			set this_subject to (subject of _msg) as Unicode text
			set encoded_subject to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of this_subject
			
			open location "todoist://addtask?content=[" & (encoded_subject) & "](message://%3C" & (_msgID) & "%3E)"
            # add delay and press return to give todoist enough time to process the input
			tell application "System Events"
				delay 0.3
				keystroke return
				delay 0.3
			end tell
		end repeat
	end if
end tell

add selected mails to Drafts:


tell application "Mail"
	set _msgs to selected messages of message viewer 0
	if (_msgs is not equal to missing value) then
		repeat with _msg in _msgs
			set _msgID to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & (message id of _msg)
			set this_subject to (subject of _msg) as Unicode text
			#		delay 1
			
			
			set encoded_subject to do shell script "/usr/bin/python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of this_subject
			
			open location "drafts5://x-callback-url/create?text=(" & (encoded_subject) & ")[message://%3C" & (_msgID) & "%3E]"
		end repeat
	end if
end tell
3 Likes

Is there any way to get the message id from an email (native mail app) on iOS using shortcuts?

not that i know… You can e.g. retrieve links for apple notes with the “View Content Graph” action, but you need to manually copy them, so this is not really practical.
For E-Mails, I flag and move them to an “ACTION” folder on the iPhone if I can’t reply directly… If I want to make sure to dont forget the E-Mail I’ll also forward it to todoist…

I did not try to create a mail rule based on a flag and automatically run the script from above… maybe this is possible…

Does anybody know and iOS 15 if this is going to be possible on your iPhone

Is there a way to use message:// or some other URL scheme to open Mail with a specific account?

Pretty sure just the standard mailto:, and the individual email specific message: are the only options Apple provides on URL schemes.

https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MailLinks/MailLinks.html

When I run @MacSparky 's script to paste in a mail link, I get an error and this message: sh: /usr/bin/python: No such file or directory. What do I need to change?

Thanks,

John

Check here for an answer. Probably you’re on Monterey, where Apple stopped included python in the OS. The link gives both a fix and a workaround