I am retrieving messages from the Google Gmail API in Node.JS, but I am having trouble creating or receiving a direct link to emails.
I am currently using the following code:
var link = 'https://mail.google.com/mail/u/0/#inbox/' + messageContent.threadId;
But, as you can see, it always goes to the user's primary mailbox ( /u/0/ ). The letters I'm trying to link are in my second and third mailboxes.
I tried to get the email mailbox number using get the message , but unfortunately it does not return this data.
I also tried the following code snippet, but it didn't work either. It just loads my primary mailboxes.
var link = 'https://mail.google.com/mail/#inbox/' + messageContent.threadId;
Does anyone know how to create a correct and direct email link?
Thanks in advance.
Test case
First, sign in with two or more Google accounts. As you can see in the image below, I logged into 3 accounts. The first (top), my main account. Others are secondary accounts.

Direct link to my main Gmail: https://mail.google.com/mail / u / 0 / # inbox /
Direct link to my second account: https://mail.google.com/mail / u / 1 / # inbox /
And the link of my third and last account: https://mail.google.com/mail / u / 2 / # inbox /
These numbers depend on how you logged in to your accounts. The first account you log in to will always be your primary account.
So take 2527bfcqed7d54c1 as an example message ID. The only thing left is to create a direct link to the message, but the problem is that we only know the emails associated with it, and not the number of incoming messages (for example, /u/2 ).
So, if the message exists in the inbox /u/2 , we cannot get a direct link. Since the API does not return the mailbox number, and https://mail.google.com/mail/#inbox/2527bfcqed7d54c1 will always be redirected to the main mailbox /u/0 .