My organisation uses a label sharing add-in to share emails across our Gmail accounts.
We want to create a way to be able to link to a specific email that, through the above add-in, we know exists in all users' accounts. We've identified that an email's MessageID is a unique identifier, and that GMail allows the MessageID as a search parameter.
This means we can create a URL that will open GMail into a search query for a MessageID that will only have 1 result. The user can then click this one result to see the email. It's not as nice as launching straight into the email in question but it's good enough.
In Gmail, the MessageID of an email can be obtained when inside an email by clicking the 3 dots top right, clicking < > Show original , it is then displayed in the page that shows (see screenshot below). We would then manually copy this (I assume automating this part of the process isn't feasible via. TextBlaze)
I would like a TextBlaze command that displays an input box for a user to paste in a MessageID which takes the form <randomidstring@url.com> and convert this into the search query URL like this:
https://mail.google.com/mail/u/0/#search/rfc822msgid%3A%3Crandomidstring%40url.com%3E
I have tried using AI to create a snippet but without success, any pointers would be appreciated.
Screenshot:
Hi @Martin_Hill Apologies for the delayed response!
I assume you want a snippet like this so that it can be directly triggered into the browser address bar by typing tb<space><snippet-shortcut>:
Note the key part is the urlencode function which correctly encodes the angle brackets so they're valid in the URL.
You can also make it so that the message ID is pulled directly from an open Gmail page - so the user doesn't need to copy/paste it:
Hi Gaurang, thanks very much for this. The second snippet was exactly what I was after, better than I had hoped was possible in fact. BUT, it worked at first, then I don't know what changed, but now it doesn't? Here's what I'm getting when running it:
[Error - No match found for selector: ".message_id".]https://mail.google.com/mail/u/0/#search/rfc822msgid%3A"Error%3A%20No%20match%20found%20for%20selector%3A%20\".message_id\"."
In case it's relevant, I run my Gmail installed as an app, i.e. the window it's in has no URL bar visible. So I was running the snippet from the search bar (with an individual email opened). I also added some key strokes to the snippet to copy it to the clipboard (is there another way?) and then mimic Esc keypress to clear the search bar. I removed those when it stopped working as a troubleshooting attempt, but no joy. Any thoughts?
Great to hear that! Regarding the error, I see the message is:
Error - No match found for selector: ".message_id".
This suggests that the "Original message" tab is not open anywhere in your browser window. I am referring to the page that opens when you do this:
In Gmail, the MessageID of an email can be obtained when inside an email by clicking the 3 dots top right, clicking < > Show original
Did you close it by accident while running the snippet? If not, a short video recording showing the issue would be great. You can also email it to me at gaurang@blaze.today
Ah, I see. I didn't realise the 'Show original' had to be open whilst running the snippet. I was just running it from within the email message I wanted to link to. With the 'Show original' open it does indeed work as expected.
Is there any way to do it without having to open the 'Show original', or automate opening of the 'Show original' window?
Alternatively, if it's not possible, when the snippet errors can a note pop up informing the user they need to "Click 3 dots > <>Show original before running this snippet" ?
Is there any way to do it without having to open the 'Show original', or automate opening of the 'Show original' window?
It's not possible to do it without opening the "Show original" window, unless - I'm not sure about this - we use the Gmail API.
It's also not possible to open the "Show original" window and then read its contents from within the same running snippet. This is something we want to support in the future, but for now, it might be simpler to open the original window manually.
can a note pop up informing the user they need to
Yes, we can show an error like so:
Although it will look a bit weird as it thinks we're trying to open a URL, because we typed it in the omnibox:
Thanks for the update Gaurang, what you've provided is still much better than the manual way I was doing it.
I'm running into an issue when using the output of this (awesome!) snippet to paste into a link in google chat. For some reason, when the MessageID contains a + symbol, Google is converting it to a space (only when pasted into a viewer friendly text link). Here's what Gemini has to say about it: Google Doc
Are any of the workarounds it suggest viable?
That's an interesting issue! I tried the workarounds it suggested as well as a couple more ideas, but none of them worked for me. This is definitely an issue in Google Chat itself, and there doesn't seem to be a way we can handle it 
Thanks @Gaurang_Tandon , appreciate you looking into it. I'll raise a support ticket with Google about it (won't be holding my breath for a resolution!)
Is there a way the snippet could check for a + character in the MessageID and give the user a warning message so at least they know not to embed it in a link?
Sure, can you try this snippet? I added an extra {if} command. This snippet will trigger
Thanks @Gaurang_Tandon, (I finally got back to this!) however this always just seems to return "Click 3 dots..."
I've got it working (see below - I copied and pasted your additional if statement into my original snippet and it worked. Not exactly sure what else is different!).
Before, the URL would just be inserted into wherever I typed it. Now a textblaze dialogue window comes up (whether or not a + exists) and I have to click the insert button.
Is there a way to bypass this or automatically click the 'Insert' button if no + exists?
Also, is it possible to have a carriage return in the Run>Notify text? I've not been able to work out how to do it.
I'm also now trying to make the similar textblaze below that will change how the link is displayed, based on whether or not the MessageID contains a +.
I know this bit is wrong:
Hyperlink:name="email" URL=https://mail.google.com/mail/u/0/#search/rfc822msgid%3A {=urlencode(message_id)}
How do I do it right?
Is there a way to bypass this or automatically click the 'Insert' button if no + exists?
Sadly, there's no way to bypass this at the moment. Please see the discussion at Autopaste & {if} - #2 by scott
is it possible to have a carriage return in the Run>Notify text?
Looks like it's not possible at the moment. I'll check if we can improve that.
I'm also now trying to make the similar textblaze below that will change how the link is displayed, based on whether or not the MessageID contains a +.
I'm not sure if I understand this. I understand we want to display the raw link so we can insert it into the browser address bar (as per Create link to a specific Gmail email using it's MessageID - #2 by Gaurang_Tandon). Is that not the case anymore? If not, can you please clarify where you're going to insert this new snippet?
Hi Gaurang, thanks for the response.
Re. your last query, both the current snippet and the one I'm trying to create are used mainly in Google Chat messages. Currently we use the existing snippet you helped me create as follows:
(I'm using the term 'URL' below to refer to the message ID gmail search URL the previous snippet outputs)
- Open the <>Show original version of an email
- Go to Chat, type a message that might include "refer to this email", highlight the word 'email', Ctrl-K and then run the snippet in the 'Type or paste a link' box to enter the URL
- The recipient can then click 'email' to view the email.
- If we get the warning that the MessageID contains a +, then we can't embed it as a hyperlink, and instead have to copy that URL, exit the link box and paste it so the whole link is visible instead (as the link will continue to work this way).
To make this workflow more efficient, I'm trying to create the following workflow:
- Open the <>Show original version of an email
- Go to Chat, type a message, then at the right place trigger the snippet that will:
a) If MessageID does not contain a + , insert the word 'email' and hyperlink it with the URL
b) If MessageID does contain a + then just insert the 'raw' URL
I see. I think you want to use the {link} command. Here's the updated snippet:
{message_id=catch({site: text; page=https://mail.google.com/*; selector=.message_id}, ""); trim=yes}
{if: message_id<>""; trim=yes}
{if: contains(message_id, "+"); trim=yes}
https://mail.google.com/mail/u/0/#search/rfc822msgid%3A{=urlencode(message_id)}
{else; trim=yes}
{link: https://mail.google.com/mail/u/0/#search/rfc822msgid%3A{=urlencode(message_id)}; trim=yes}
email
{endlink; trim=yes}
{endif; trim=yes}
{else; trim=yes}Error! Open *<>Show original* before running this snippet!{endif}
The important bit is:
{link: https://mail.google.com/mail/u/0/#search/rfc822msgid%3A{=urlencode(message_id)}; trim=yes}
email
{endlink; trim=yes}