To copy my Gmail link, you have to shoot a dispatch with Google Apps Script, the Gmail API returns a unique ID that you can use to determine the URL of the dispatch communication in your transferred particulars.

All dispatch dispatches in your Gmail inbox have an endless web address and you can add this URL to your bookmarks to snappily pierce that communication in the future.

You can save these communication links in your task list or your meeting notes as they give an important environment to the discussion.

Any email message is Gmail follows a standard format for the URL as shown below.

https://mail.google.com/mail/u/<<UserId>>/#label/<<Label>>/<<UniqueId>>

The User Id is the successional ID of the presently- logged Gmail account ( dereliction is 0). The Marker is the name of the Gmail marker that the communication is in (or use all). The UniqueId is a unique ID that Gmail assigns to each communication.

The key then’s the UniqueId that’s internally assigned by Gmail.

When you shoot a dispatch with Google Apps Script, the Gmail API returns a unique ID that you can use to determine the URL of the dispatch communication in your transferred particulars.

Then’s a simple procedure to shoot a dispatch that’s base64 decoded.

const sendGmailMessage = (mimeText) => {
  const GMAIL_API = 'https://gmail.googleapis.com/upload/gmail/v1/users/me/messages/send';
  const params = {
    method: 'POST',
    contentType: 'message/rfc822',
    headers: {
      Authorization: `Bearer ${ScriptApp.getOAuthToken()}`,
    },
    payload: mimeText,
  };
  const response = UrlFetchApp.fetch(GMAIL_API, params);
  const { id: messageId } = JSON.parse(response.getContentText());
  return messageId;
};

There are many ways to get the URL {permalink} of the email message, especially now that you know the message ID of the outgoing email message.

const getEmailMessageUrl = (messageId) => {
  return `https://mail.google.com/mail/u/0/#all/${messageId}`;
};

2: Use Apps Script to get the email thread URL

In this second method, we have to get the related thread of the email message. After that, we then get the URL of the first message in the thread.

const getThreadUrl = (messageId) => {
  const message = GmailApp.getMessageById(messageId);
  return message.getThread().getPermalink();
};

3: Use the Message-Id in Email Header

This is my favorite approach because it’s the most dependable. When you shoot a dispatch communication, a unique communication ID is assigned to the dispatch communication by the transferring service.

This communication ID is stored in the Communication-Id title of the dispatch communication. It is also used by your dispatch customer to group dispatches in the same discussion.

Gmail provides a special rfc822msgid hunt driver to search emails by communication ID. We can use this hunt driver to get the URL of the dispatch communication.

const getMessageUrl = (messageId) => {
  const message = GmailApp.getMessageById(messageId);
  const rfc822Id = message.getHeader('Message-Id');
  const searchQuery = `rfc822msgid:<${rfc822Id}>`;
  return `https://mail.google.com/mail/u/0/#search/${searchQuery}`;
};

Leave a Reply

Your email address will not be published.