Using Gmail message source, generate direct link
Asked Answered
D

3

10

So using the gmail message source is it possible to generate, a link to the message/thread in GMail's own interface?

on http://productforums.google.com/forum/#!topic/gmail/goChl1gG0NQ they use the following

https://mail.google.com/mail/#all/<HexEncodeMessageID>

Is this related to the Message=ID header found in the mail's source?

Message-ID: <[email protected]>

The discussion Find Gmail url-IDs via IMAP seems to only give IMAP based solutions.

Diffusive answered 30/5, 2013 at 3:32 Comment(0)
C
11

Update

This bookmarklet no longer works. See Benjamin Ziepert's update.

Original Answer

I decided to make a bookmarklet to help automate this.

javascript:window.location="https://gmail.com/#search/rfc822msgid:"+encodeURIComponent(window.document.body.innerHTML.match(/Message-ID: &lt;(.*)&gt;/i)[1])+"/"+encodeURIComponent(window.location.search.toString().slice(1).split('&').filter(function(x){return x.slice(0,3) == "th="})[0].slice(3));

Save this link on your bookmarks bar. To get a direct link to a message, choose "Show original" on the dropdown for that message, and then click the bookmarklet on the new page that opens.

If anyone has suggestions for a clean way to do this without having to click show original, I'm all ears.

Caesarean answered 19/12, 2013 at 20:49 Comment(6)
Message-ID should be changed to Message-Id for it to workAlleras
Good point. Headers are case-insensitive, so I've updated the regex to ignore case.Caesarean
An updated version for the bookmarklet: javascript:window.open("https://mail.google.com/mail/u/0/#search/rfc822msgid%3A" + encodeURIComponent(document.getElementsByClassName('message_id')[0].innerHTML.slice(4, -4)), "_self");Shaffert
Top answer no longer works. @BenjaminZiepert's solution does though. Thank you.Outsoar
This is fantastic! I'll ask as a separate question, but do you know if there is a programmatic way to include the URL that this bookmarklet produces when forwarding an email? I want to forward emails to a task management app (Trello) and include the direct link to the email so that it is easier to go from Trello back to the original email in Gmail. Thanks.Extravagance
Doesn't work for me. I have this link to the original mail.google.com/mail/u/… - how should the link look?Pizarro
R
8

The "HexEncodeMessageID" that you refer to (and that occurs in links such as https://mail.google.com/mail/#inbox/14197d2548c9da1a) is unfortunately different from the RFC822 message ID (which occurs in the source of the email).

I do not know of any way to get a direct link to an email using the RFC822 message ID, but it is possible to search for a particular RFC822 message ID in Gmail (see GMail doc):

in:anywhere rfc822msgid:[email protected]

You can turn this into a link:

https://mail.google.com/mail/#search/in%3Aanywhere+rfc822msgid%[email protected]

(Don't forget that the message id should be URL-encoded. You can also just type the search in your GMail and copy the resulting URL afterwards.)

The problem with this link is that it does not send you to the mail directly, but to a search result page with a single hit. But this might be good enough for some applications.

The advantage is: The RFC822 is the same in your account and in the account of the sender. So if you want to refer to a given email in an email/chat, you can provide this search link (assuming the recipient also uses GMail). With the "HexEncodeMessageID" this would not work, because it is different in every account (according to my own experiments).

One last thing: the link only works when you are already logged in.

Renascent answered 8/10, 2013 at 12:1 Comment(0)
P
1

Here's an updated bookmarklet over what Benjamin Ziepert suggested. Basically with removed /u/0 part to make it a little more account-independent.

javascript:window.open("https://mail.google.com/mail/#search/rfc822msgid%3A" + encodeURIComponent(document.getElementsByClassName('message_id')[0].innerHTML.slice(4, -4)), "_self");

Usage: Save this link on your bookmarks bar. To get a direct link to a message, choose "Show original" on the dropdown for that message, and then click the bookmarklet on the new page that opens.

Pita answered 6/1, 2019 at 21:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.